Skip to content
Official PYQ · 2001

GATE CS 2001 Q2.22 — Concurrency and Synchronization

Explain with AI

Consider Peterson's algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below.

repeat
    flag[i] = true;
    turn = j;
    while (P) do no-op;
    Enter critical section, perform actions, then
    exit critical section
    Flag[i] = false;
    Perform other non-critical section actions.
Until false;

For the program to guarantee mutual exclusion, the predicate P in the while loop should be

Choose one option
View worked solution

Answer: B

In Peterson's algorithm for mutual exclusion between two processes ii and jj:

  • The boolean array flag represents the intent of each process to enter its critical section. Setting flag[i] = true means process ii wants to enter.
  • The variable turn resolves conflicts when both processes try to enter simultaneously. By setting turn = j, process ii politely yields the turn to process jj.

For process ii to safely enter its critical section, it must wait (busy-wait) if and only if:

  1. The other process jj wants to enter the critical section: flag[j] == true.
  2. It is currently process jj's turn to enter: turn == j.

Thus, the busy-waiting condition (predicate PP) in the while loop of process ii must be:

flag[j]=true and turn=j\text{flag}[j] = \text{true} \text{ and } \text{turn} = j

If either of these conditions is false (e.g., if process jj is not interested, or if the turn has been given back to ii), process ii breaks out of the loop and safely enters its critical section, ensuring mutual exclusion.

Therefore, the correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Concurrency and Synchronization questions