GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 2.22

Peterson waiting predicate

Operating Systems · Synchronization & Concurrency · Full GATE CSE 2001 paper

GATE 2001, Q2.22 2 marks · MCQ
Report issue

Synchronization & Concurrency

Question 2.22, GATE 2001: In Peterson’s entry code for process i: set flag[i]=true; turn=j; while(P) wait; enter critical section; then clear flag[i]. Choose P: flag[j] AND turn=i; flag[j] AND turn=j; flag[i] AND turn=j; flag[i] AND turn=i. Distinguish progress from safety alone.
Tap to enlarge
Your answer
Answer & solution

Answer: B for Peterson mutual exclusion with progress (no official key was published)

Step 1: Process i announces intent with flag[i]=true and sets turn=j, yielding priority to j. It should wait only while j also wants entry and j has priority: flag[j] AND turn=j, option B.

Step 2: If both flags are true, the last write to turn selects one waiting process and lets the other enter. If j leaves, it clears flag[j], immediately releasing i’s wait regardless of turn. Atomic reads/writes and sequentially consistent ordering are assumed.

Qualification: The literal question mentions only mutual exclusion. Option C, testing its own flag with turn=j, can preserve exclusion while blocking a lone entrant forever. It is not Peterson’s correct solution because progress fails. B is the predicate satisfying the intended full critical-section requirements.

Original paper, page 7