GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 28(b)

Constructing a resource completion order

Operating Systems · Deadlocks · Full GATE CSE 1994 paper

GATE 1994, Q28(b) Descriptive
Report issue

Deadlocks

Question 28(b), GATE 1994: Resource types r1,r2,r3 have respectively 2,3,2 instances. Assignments are r1→P1 and r1→P0; r2→P1, r2→P2 and r2→P3; r3→P0, leaving one r3 instance free. Outstanding requests are P1→r1; P0→r2 and P0→r3; P2→r3; P3→r1 and two P3→r2 arrows. If the system is not deadlocked, give a safe completion sequence.
Question 28(b), GATE 1994: Resource types r1,r2,r3 have respectively 2,3,2 instances. Assignments are r1→P1 and r1→P0; r2→P1, r2→P2 and r2→P3; r3→P0, leaving one r3 instance free. Outstanding requests are P1→r1; P0→r2 and P0→r3; P2→r3; P3→r1 and two P3→r2 arrows. If the system is not deadlocked, give a safe completion sequence.
Question 28(b), GATE 1994: Resource types r1,r2,r3 have respectively 2,3,2 instances. Assignments are r1→P1 and r1→P0; r2→P1, r2→P2 and r2→P3; r3→P0, leaving one r3 instance free. Outstanding requests are P1→r1; P0→r2 and P0→r3; P2→r3; P3→r1 and two P3→r2 arrows. If the system is not deadlocked, give a safe completion sequence.
Question 28(b), GATE 1994: Resource types r1,r2,r3 have respectively 2,3,2 instances. Assignments are r1→P1 and r1→P0; r2→P1, r2→P2 and r2→P3; r3→P0, leaving one r3 instance free. Outstanding requests are P1→r1; P0→r2 and P0→r3; P2→r3; P3→r1 and two P3→r2 arrows. If the system is not deadlocked, give a safe completion sequence.
Tap to enlarge
Answer & solution

Answer: P2 → P0 → P1 → P3. (no official key was published)

Use the available-vector test in resource order (r1,r2,r3). Initially Work=(0,0,1). P2 requests (0,0,1), so its request fits. On completion its original holding (0,1,0) returns to the available pool, giving Work=(0,1,1). It is important not to count the temporarily granted r3 twice: allocation-based reduction adds only the allocation it held before this simulated completion.

Next P0 requests (0,1,1), exactly within Work. It finishes and releases original allocation (1,0,1), making Work=(1,1,2). P1's outstanding request (1,0,0) now fits; releasing its original allocation (1,1,0) gives Work=(2,2,2). P3 can finally receive (1,2,0); releasing its original holding (0,1,0) gives Work=(2,3,2), the complete resource inventory. Thus P2,P0,P1,P3 is a valid completion sequence.

Indeed the initial choices are forced by the displayed requests: P0 initially lacks r2, while P1 and P3 lack r1. After P2, P0 is the only remaining satisfiable process. After P0, P3 still needs two free r2 instances but only one is available, forcing P1 before P3. Under simultaneous satisfaction of the displayed request vectors this order is therefore unique. As in part (a), “safe” means all these displayed requests can be satisfied and the processes finish; the graph does not state maximum possible future claims, so a stronger Banker's-algorithm safety assertion is outside the supplied data.

Original paper, page 7