Skip to main content

Deadlock detection with allocation matrices

Short answer

Total resources are 7 A, 2 B, 6 C instances. Sum allocations equal totals, so Available is (0,0,0). Detection shows all processes can finish (P0→P2→P1→P3→P4), so system is not deadlocked. If P2 requests (0,0,1), only P0 finishes; P1, P2, P3, P4 become deadlocked.

Consider a system with 5 processes P0 through P4 and three resources types A, B, C. Resource type A has 7 instances, B has 2 and C has 6 instances. Suppose at t0 time we have following state:

ProcessAllocation (A B C)Request (A B C)Available (A B C)
P00 1 00 0 00 0 0
P12 0 02 0 2
P23 0 30 0 0
P32 1 11 0 0
P40 0 20 0 2
a) Is the given system in deadlock state?
b) Suppose P2 makes an additional request (0, 0, 1) what will be the effect of this request to the system?

Method

Use the deadlock detection algorithm: Work = Available; a process is marked Finish if its Request ≤ Work, and then Work = Work + Allocation. Processes that cannot be marked at the end are deadlocked.

Total (A, B, C) = (7, 2, 6). Sum of allocations = (0+2+3+2+0, 1+0+0+1+0, 0+0+3+1+2) = (7, 2, 6), so Available = (0, 0, 0).

a) State at t0

Work = (0, 0, 0)

StepProcessRequestRequest ≤ Work?Work after
1P00 0 0yes0 0 0 + 0 1 0 = 0 1 0
2P20 0 0yes0 1 0 + 3 0 3 = 3 1 3
3P12 0 2yes3 1 3 + 2 0 0 = 5 1 3
4P31 0 0yes5 1 3 + 2 1 1 = 7 2 4
5P40 0 2yes7 2 4 + 0 0 2 = 7 2 6

All processes can finish, in the order P0, P2, P1, P3, P4 (other orders also work).

Answer (a): The system is NOT in a deadlocked state.

b) P2 additionally requests (0, 0, 1)

Now Request(P2) = (0, 0, 1), and Available is still (0, 0, 0).

Work = (0, 0, 0)

  • P0: Request (0,0,0) ≤ Work, so P0 finishes; Work = (0, 1, 0).
  • P1: needs (2,0,2) > (0,1,0), cannot proceed.
  • P2: needs (0,0,1), but C = 0, cannot proceed.
  • P3: needs (1,0,0), but A = 0, cannot proceed.
  • P4: needs (0,0,2), cannot proceed.

No further process can proceed. Only P0 finishes, and the resources it releases are too few to help the others.

Answer (b): The system becomes deadlocked, with P1, P2, P3 and P4 deadlocked. The system must then recover, e.g. by aborting one of these processes or preempting its resources.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 7 questions →