GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 19(c)

Swap P2 resource acquisition order

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

GATE 2001, Q19(c) Descriptive
Report issue

Synchronization & Concurrency

Question 19(c), 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. Exchange Q1 with Q3 and Q2 with Q4.
Question 19(c), 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. Exchange Q1 with Q3 and Q2 with Q4.
Tap to enlarge
Answer & solution

Answer: Mutual exclusion fails after reordering, but there is no resource deadlock (no official key was published)

After swapping the the paper operations, both processes check/set R1 and then check/set R2. Name the new P2 order Q1′=test R1, Q2′=set R1, Q3′=test R2, Q4′=set R2, followed by use and the original releases. A violating interleaving is S1,Q1′,S2,Q2′,S3,Q3′,S4,Q4′, followed by overlapping S5 and Q5. Both tests of each free flag precede either write to that flag, so both reach their use intervals. This shows why a real atomic lock operation is required.

There is no resource deadlock in the reordered the paper protocol: a process waiting on R2 has already passed the R1 test. Any competing process that made R2 busy has also passed both tests and can finish and release; it cannot be waiting to acquire R1 afterward. This excludes a circular resource wait, assuming a runnable process eventually runs. It does not promise fairness or fix mutual exclusion.

Its one-shot nonoverlap and self-wait deadlock from parts (a),(b) remain.

Original paper, page 10