Question: Extend Petersons SW-based MUTEX solution to work with n processes. // This is Peterson's Solution int c1 = 0, c2 = 0, will_wait; cobegin p1:

  1. Extend Petersons SW-based MUTEX solution to work with n processes.

// This is Peterson's Solution

int c1 = 0, c2 = 0, will_wait;

cobegin p1: while(1) {

c1 = 1; will_wait = 1; while(c2 && (will_wait ==1); //loop DO-CS; c1 = 0; prog1 outside CS;

}

//

p2: while(1) { c2 = 1; will_wait = 2; while(c1 && (will_wait ==2); //loop DO-CS; c2 = 0;

prog1 outside CS;

} coend;

- Process p_i sets flag c_i to indicate the intent to enter the CS. Variable "will_wait" breaks possible race conditions. p_i setting "will_wait" to its pid announces to the other process that it is willing to wait if both processes happen to attempt to enter the CS at the same time. The solution guarantees mutual exclusion (MUTEX) and prevents all forms of blocking.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!