GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 58

Two intent flags give mutual exclusion but may deadlock

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

GATE 2007, Q58 2 marks · MCQ
Report issue

Synchronization & Concurrency

Question 58, GATE 2007: Shared flags wants1,wants2 are initially false. P1 executes:
while(true) { wants1=true; while(wants2==true); /* critical section */ wants1=false; }
P2 executes:
while(true) { wants2=true; while(wants1==true); /* critical section */ wants2=false; }
The source places each remainder-section comment after its loop. Under atomic sequentially consistent flag operations, which statement is intended?
Options:
(A) Mutual exclusion is not ensured
(B) Bounded waiting is not ensured
(C) Critical sections must alternate strictly
(D) Deadlock is not prevented, but mutual exclusion is ensured
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Approach. Test safety and progress separately. Two critical sections cannot overlap because each entrant advertises its intent. But if both advertise before either tests, neither can reach the instruction clearing its flag.

2. Derivation and interpretation. Under the standard sequentially consistent, atomic-read/write pseudocode model, each process sets its own wants flag before testing the other's flag and keeps it true throughout its critical section. Thus both cannot pass their tests and overlap in the critical section: whichever passes first prevents the other entering until it clears its flag. However, if both set their flags before either tests the other, each spins forever, giving deadlock. Thus D describes the decisive combination: mutual exclusion holds but deadlock prevention fails. Strict alternation is not required; one process can repeatedly enter while the other does not request entry. Option B needs care: under a broad interpretation that bounded waiting guarantees eventual entry, deadlock also violates it. In the usual bounded-overtaking formulation, distinguish this progress failure from another process overtaking a waiter indefinitely; the latter cannot occur here. D is the intended most specific answer, while the phrasing of B can be read more broadly.

Original paper, page 14