GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 22(a)

Safety of the Banker state

Operating Systems · Deadlocks · Full GATE CSE 1996 paper

GATE 1996, Q22(a) Descriptive
Report issue

Deadlocks

Question 22(a), GATE 1996: Three processes P0,P1,P2 share resource types R0,R1,R2. Maximum total claims are P0=(4,1,2), P1=(1,5,1), P2=(1,2,3). Current allocations are P0=(1,0,2), P1=(0,3,1), P2=(1,0,2), and Available=(2,2,0). Show that this can be a state admitted by the Banker’s algorithm.
Question 22(a), GATE 1996: Three processes P0,P1,P2 share resource types R0,R1,R2. Maximum total claims are P0=(4,1,2), P1=(1,5,1), P2=(1,2,3). Current allocations are P0=(1,0,2), P1=(0,3,1), P2=(1,0,2), and Available=(2,2,0). Show that this can be a state admitted by the Banker’s algorithm.
Tap to enlarge
Answer & solution

Answer: Safe sequence P1→P2→P0; Work evolves (2,2,0)→(2,5,1)→(3,5,3)→(4,5,5). (no official key was published)

Step through it (5 steps)

The table heading “Maximum Need” gives total claims, not outstanding requests. Subtract each allocation to obtain remaining Need: P0=(3,1,0), P1=(1,2,0), P2=(0,2,1). The total resource vector is Available plus all allocations, namely (4,5,5); every maximum is individually within this total.

Run the safety test with Work=(2,2,0). P0 cannot finish yet because it needs 3 units of R0 but only 2 are free. P2 cannot finish because it needs one R2 while none is free. P1 can finish since (1,2,0) is componentwise at most (2,2,0). After it finishes, Work increases by its current allocation (0,3,1), yielding (2,5,1). Adding allocation, rather than maximum, is correct: its extra temporary requests are returned too, leaving the net increase equal to the allocation it already held.

Now P2's need (0,2,1) fits, so its completion releases (1,0,2) and Work becomes (3,5,3). Finally P0's need (3,1,0) fits; releasing (1,0,2) yields (4,5,5). Thus P1,P2,P0 is a safe sequence, proving that all claims can be satisfied in a suitable order. Safety does not assert that every possible future request is immediately grantable; it establishes at least one completion schedule from the current allocations.

Original paper, page 10