Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct: P1: while(true){wants1=true; while(wants2==true); /*CS*/ wants1=false;} P2: while(true){wants2=true; while(wants1==true); /*CS*/ wants2=false;} Here wants1 and wants2 are shared variables initialized to false. Which one of the following statements is TRUE about the above construct?
- AIt does not ensure mutual exclusion
- BIt does not ensure bounded waiting
- CIt requires that processes enter the critical section in strict alternation
- It does not prevent deadlocks, but ensures mutual exclusion
Explanation
If P1 sets wants1=true and, before checking wants2, P2 sets wants2=true, then each process's while-condition (checking the OTHER's flag) becomes true — both wait forever, a deadlock. However, in every interleaving, mutual exclusion still holds: neither process can enter its critical section while the other's flag is set, so they never enter simultaneously. So the construct does not prevent deadlock, but does ensure mutual exclusion (unlike the flawed algorithms that fail mutual exclusion itself).
Source: GATE CS 2007 (2007)
This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.