Deadlock
Deadlock analysis separates a present inability to progress from a risk created by future demands. Use a resource graph for structure, a safety table for multiple resource types, and a worst-case holding argument for identical resources.
3.1 Conditions and resource graphs
Past papers · CS 2014–2026 (23 papers): 5 questions, 8 marks
Deadlock needs mutual exclusion, hold-and-wait, no forced resource preemption, and circular wait. Their presence as general system policies does not prove that the current allocation is deadlocked.
A request edge points from process to resource type; an assignment edge points from a resource instance to its holder. With one instance of every type, a cycle of actual request and assignment edges characterises deadlock. With multiple instances, a cycle is necessary but not sufficient. A wait-for graph removes resource nodes and connects a waiting process to the holder it needs, under the single-instance model.
Two processes each hold the resource requested by the other.
| Strategy | Decision rule |
|---|---|
| Prevention | Break a necessary condition, for example by imposing resource order |
| Avoidance | Use declared future limits; refuse an allocation that makes the state unsafe |
| Detection | Allow allocation, then inspect actual outstanding requests |
| Recovery | Abort selected processes or preempt recoverable resources; consider rollback and repeated victim selection |
A claim edge denotes a possible future request, not a present blocked request. A cycle containing claims indicates an unsafe possibility; inspect the question's edge definitions before declaring deadlock. Recovery must remove every blocking cycle: aborting a process on one cycle can leave another cycle intact.
Starvation is indefinite denial while other work progresses. Livelock has activity but no useful progress. Neither term is interchangeable with deadlock.
3.2 Identical reusable resources
Past papers · CS 2014–2026 (23 papers): 4 questions, 5 marks
3.3 Banker's safety and request tests
Past papers · CS 2014–2026 (23 papers): 4 questions, 8 marks
Select an unfinished process whose Need fits Work, simulate its completion, add its current allocation to Work, and mark it finished. Repeat. Finishing all processes gives a safe sequence. If the scan gets stuck, the state is unsafe under the declared maxima; it need not already be deadlocked.
3.4 Detection with current requests
For multiple instances, initialise Work to Avail and use the current outstanding Request matrix in place of future Need. Processes holding no resources can initially be marked finished for detecting resource-holding deadlock. Repeatedly satisfy a feasible current request and release that process's allocation in the simulation. Resource-holding processes left unfinished form the detected deadlocked set under this model.
Banker's safety and detection look similar but answer different questions. Detection uses what processes are blocked on now; avoidance uses the maximum that they may still ask for. The straightforward safety scan takes time for processes and resource types.
Last-minute recall
- No cycle means no resource deadlock in the resource-allocation model.
- A cycle is sufficient only with single-instance resource types.
- Safe implies not deadlocked; unsafe does not imply already deadlocked.
- Need is Max minus Alloc, never Max minus Avail.
- Safety testing is a simulation; do not consume actual resources.
- Recovery must consider whether a resource can be safely preempted.