Resource Models, WFG, CMH Probe, Mitchell-Merritt, Chandy Diffusion
Deadlock — Same Idea, Harder Problem
In an OS, deadlock detection is a single-machine wait-for graph traversal: cheap. In a distributed system, the same wait-for graph is *split across nodes*. No single node sees the whole graph. Even reconstructing it takes communication — and while you collect, the graph changes.
The exam wants you fluent in three things: the resource model that determines what counts as a deadlock; the WFG criterion for each model; and the detection algorithms for each.
Five Resource Models
- Single resource — at most one pending request per process.
- AND — process needs ALL requested resources together.
- OR — process needs ANY ONE of the requested resources.
- AND-OR — arbitrary combination, e.g., .
- P-out-of-Q — needs any of resources.
The deadlock criterion changes with the model.
Cycle vs Knot
Single-resource and AND: deadlock iff WFG has a cycle.
OR: a cycle is NOT enough. A process in a cycle might also be waiting on a resource outside the cycle — which could be granted, breaking the wait. Only when the SCC has *no outgoing edges* — a knot — is every process in it permanently blocked.
Definition: a knot is an SCC where every node reaches only other knot nodes. Equivalently, the SCC is a sink in the condensation graph.
Common exam mistake: "OR deadlock iff cycle." Wrong — it must be a knot.
Three Strategies
Prevention — design so deadlock can't happen (pre-order resources globally; require pre-claim). Slow, may starve.
Avoidance — needs global state knowledge (Banker's-style). Expensive in DS where there is no global state.
Detection — run an algorithm when deadlock is suspected; then preempt and restart. Most popular in DS because it's the only one that doesn't need expensive global state.
Once detected, three recovery options: process termination, resource preemption, or rollback to a checkpoint.
Control Organisations
Centralised — one site builds the global WFG. Single point of failure.
Distributed — every node equally responsible; uses waves/probes.
Hierarchical — tree of sites; the lowest common ancestor of involved sites detects.
Phantom Deadlock
Because we collect WFG dependencies non-atomically, while we collect, the WFG changes. A resource is released; a process unblocks. The cycle we "see" in the assembled WFG may never have existed simultaneously. This is a false or phantom deadlock. Algorithms try to reduce it (Ho-Ramamoorthy collects twice; CMH uses persistent dependencies).
Algorithms By Model
Ho-Ramamoorthy (Centralised)
2-phase: collect process status from each site twice; keep only edges in both snapshots. 1-phase: each site keeps Process Status Table (per process: held/waited) + Resource Status Table (per resource: holder/waiter). Edge valid iff both tables agree.
Chandy-Misra-Haas (AND, Distributed) — The Probe
A blocked sends a probe along its outgoing dependency edges:
- = initiator.
- = sender.
- = receiver.
forwards the probe to when is blocked waiting on . When receives a probe:
- If is blocked AND not yet noted dependency on AND not yet replied to — note the dependency.
- **If → deadlock detected.**
- Else forward the probe along 's own dependency edges.
Worked trace on a 4-cycle :
1. blocks; sends probe to . 2. blocked on ; forwards probe. 3. blocked on ; forwards probe. 4. blocked on ; forwards probe. 5. receives probe with → deadlock detected.
Four messages for a 4-cycle. General bound: where sites, processes per site.
Mitchell-Merritt (Single-Resource) — Label Passing
Each node has a public and a private label, initially equal.
- Block: pick a new unique private value; set public = private.
- Activate: unblock.
- Transmit: blocked node with copies into — propagates labels backward.
- Detect: a node receiving its own public label back ⇒ deadlock. Highest-label-in-cycle detects.
Key: probes travel OPPOSITE to WFG edges.
Chandy Diffusion (OR Model)
Initiator sends to every in its dependent set. Each blocked , on receiving the FIRST (engaging) query for initiator , forwards queries to its own dependent set and waits. Replies propagate back; if initiator gets replies from all branches and — declares deadlock.
Algorithm Choice Cheat-Sheet
| Model | Algorithm | |---|---| | Single resource | Mitchell-Merritt, Ho-Ramamoorthy | | AND | Chandy-Misra-Haas probe | | OR | Chandy diffusion | | AND-OR | Repeated OR tests over conjunctive sub-clauses |
What You Walk In Carrying
Five resource models. Cycle vs knot criterion (knot for OR). Three handling strategies (detection wins in DS). Three control organisations. Phantom-deadlock concept. Ho-Ramamoorthy 1/2-phase tables. CMH probe format + detection rule . Mitchell-Merritt label-passing in OPPOSITE direction. Chandy diffusion for OR. Algorithm-by-model table.