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:
-
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
Get step-by-step solutions from verified subject matter experts
