GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 22(b)

Testing a Banker resource request

Operating Systems · Deadlocks · Full GATE CSE 1996 paper

GATE 1996, Q22(b) Descriptive
Report issue

Deadlocks

Question 22(b), 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). Determine what happens when P0 requests one unit of R1.
Question 22(b), 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). Determine what happens when P0 requests one unit of R1.
Tap to enlarge
Answer & solution

Answer: Defer P0’s request: tentative Available=(2,1,0) is unsafe although the unit is available. (no official key was published)

Step through it (4 steps)

The request vector is R=(0,1,0). First check R<=Need0=(3,1,0), so the request does not exceed P0's remaining claim. Also R<=Available=(2,2,0), so the requested unit is physically available. These necessary checks alone do not justify granting it.

Tentatively allocate the unit. Available becomes (2,1,0), P0's allocation becomes (1,1,2), and P0's remaining need becomes (3,0,0). The other needs remain P1=(1,2,0), P2=(0,2,1). Begin the safety test with Work=(2,1,0). P0 cannot finish because 3>2 in R0; P1 cannot finish because 2>1 in R1; P2 cannot finish because it needs 2 R1 and 1 R2, while only 1 R1 and 0 R2 are free. No process can be the first in a guaranteed completion sequence.

The tentative state is therefore unsafe. The Banker rolls back the tentative change and makes P0 wait, preserving Available=(2,2,0) and the original safe allocations. This is not a claim that the request is invalid or that an actual deadlock has already occurred. It is a refusal to enter a state from which completion under all declared maximum claims cannot be guaranteed. The one free unit's availability is precisely why a full safety test, rather than a simple availability check, is needed.

Original paper, page 10