Consider Peterson's algorithm for mutual exclusion between two concurrent…

GATE · Computer Science · 2001

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

repeat
   flag[i] = true;
   turn = j;
   while (P) do no-op;
   enter critical section, perform actions, and 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:

  1. A.

    flag[j] == true and turn == i

  2. B.

    flag[j] == true and turn == j

  3. C.

    flag[i] == true and turn == j

  4. D.

    flag[i] == true and turn == i

Attempted by 407 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…