GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 19(b)

Exhibit a deadlocking interleaving

Operating Systems · Deadlocks · Full GATE CSE 2001 paper

GATE 2001, Q19(b) Descriptive
Report issue

Deadlocks

Question 19(b), 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(b), 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: S1, S2, Q1, Q2, then P1 waits at S3 and P2 waits at Q3 (no official key was published)

Initially both flags are free. Let P1 pass S1 and execute S2, so R1 becomes busy. Let P2 pass Q1 and execute Q2, so R2 becomes busy. P1 now spins in S3 waiting for R2; P2 spins in Q3 waiting for R1. Neither can reach its use or release operations. The wait-for graph is P1→P2→P1: each holds its first resource while waiting for the other.

P2 then spins at Q3 on R1, the flag it set itself. P1 spins at S1 on R1. No process can reach a release. This is a self-wait plus a blocked competitor, rather than the intended two-resource circular wait.

Original paper, page 10