GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 19(a)

Find a mutual-exclusion violation

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

GATE 2001, Q19(a) Descriptive
Report issue

Synchronization & Concurrency

Question 19(a), GATE 2001: GFG variant: P1 executes S1 wait until R1 free; S2 set R1 busy; S3 wait until R2 free; S4 set R2 busy; S5 use both; S6 free R1; S7 free R2. P2 executes Q1 wait until R2 free; Q2 set R2 busy; Q3 wait until R1 free; Q4 set R1 busy; Q5 use both; Q6 free R2; Q7 free R1. Initially both free. Each test and subsequent set is a separate operation.
Question 19(a), GATE 2001: GFG variant: P1 executes S1 wait until R1 free; S2 set R1 busy; S3 wait until R2 free; S4 set R2 busy; S5 use both; S6 free R1; S7 free R2. P2 executes Q1 wait until R2 free; Q2 set R2 busy; Q3 wait until R1 free; Q4 set R1 busy; Q5 use both; Q6 free R2; Q7 free R1. Initially both free. Each test and subsequent set is a separate operation.
Tap to enlarge
Answer & solution

Answer: Yes: with one-shot execution and atomic reads and writes, the opposite acquisition order prevents overlapping use (no official key was published)

Program, assume each individual flag read or write is atomic, but test-and-set is not, and each process executes its printed sequence once. Mutual exclusion of the actual use intervals S5 and Q5 is nevertheless guaranteed. Suppose the intervals overlapped. Neither process could yet have released a resource. P2 must therefore have passed its R1 test Q3 before P1 sets R1 at S2, giving Q3<S2. Similarly P1 must pass its R2 test S3 before P2 sets R2 at Q2, giving S3<Q2. Program order imposes S2<S3 and Q2<Q3. Combining yields the impossible strict cycle S2<S3<Q2<Q3<S2. Hence an overlapping execution is impossible. Separate tests and sets alone are not enough to prove a race in this particular opposite-order program.

The only possible intervening freeing operation is P1’s S6, which follows completion of S5. Therefore P2 cannot reach Q5 before P1 finishes its use. This is poor progress behavior, not an overlapping-use counterexample. These conclusions concern the printed one-shot programs; an unspecified outer repetition loop or non-atomic/memory-reordered implementation is a different model.

Original paper, page 10