Consider Peterson's algorithm for Mutual Exclusion between two concurrent processes $w$ and $f$. The program executed by the processeses are shown below:
Process w |
Process f |
repeat
flag[w]=true;
turn=f;
while(P) do
no-operation;
Enter critical section,
perform actions,
exit critical section
flag[w]=false;
perform non critical section actions
until false;
|
repeat
flag[f]=true;
turn=w;
while(Q) do
no-operation;
Enter critical section,
perform actions,
exit critical section
flag[f]=false;
perform non critical section actions
until false;
|
For the program to guarantee Mutual Exclusion the predicate $P$ in the while loop should be
- flag[f]=true and turn = w
- flag[f]=true and turn=f
- flag[w]=true and turn=f
- flag[w]=true and turn=w