Saral Shiksha Yojna
Courses/Distributed Systems

Distributed Systems

CS3.401
Prof. Kishore KothapalliMonsoon 2025-264 credits
Revision Notes/Unit 6 — Distributed Deadlock Detection/Resource Models, WFG, CMH Probe, Mitchell-Merritt, Chandy Diffusion

Resource Models, WFG, CMH Probe, Mitchell-Merritt, Chandy Diffusion

NotesStory

Intuition

A deadlock in a distributed system is the same idea as in an OS — a cycle of processes each waiting for a resource held by another. But the DETECTION criterion depends on the resource model: in Single-resource and AND models a cycle in the wait-for graph suffices; in OR (a process needs any one of many resources) you need a stronger structure called a knot (an SCC with no outgoing edges). Three classical algorithms — Chandy-Misra-Haas probe, Mitchell-Merritt label-passing, Chandy diffusion — implement detection for different models.

Explanation

When is a system deadlocked? A set of processes where each is blocked waiting for a resource held by another in the set. Different resource models give different deadlock criteria.

Resource Request 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.

Wait-For Graph (WFG). Nodes = processes; edge iff is blocked waiting on . Deadlock criterion: in Single-resource and AND models, WFG has a cycle ⇒ deadlock. In OR model, only a knot ⇒ deadlock (cycle alone is insufficient).

Knot — definition. A strongly connected component (SCC) where every node reaches *only* other knot nodes (= SCC with no outgoing edge to non-knot nodes). Equivalently: an SCC that is also a sink in the condensation graph. Knot ⇒ deadlock in OR; nodes outside the knot whose all paths lead in are *also* deadlocked.

Three deadlock-handling strategies. Prevention — design so deadlock can't happen (e.g., pre-order resources globally). Slow, may starve. Avoidance — needs global state knowledge (Banker's-style); expensive in DS. Detection — run an algorithm when deadlock is suspected, then preempt & restart. Most popular in DS because the other two need expensive global state.

Three handling-once-detected. Process termination (abort one or more in the cycle). Resource preemption (forcibly take a resource). Rollback (rollback a process to a checkpoint without that resource).

Three 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; lowest common ancestor of involved sites detects.

Phantom (false) deadlock. Global state is not captured atomically; while collecting dependencies, the WFG itself changes (e.g., a resource is released). The cycle we 'see' may never have actually existed simultaneously.

Ho-Ramamoorthy 2-phase (centralised). Collect process status from each site TWICE. Build dependency graph from only those dependencies that appear in BOTH snapshots. Still vulnerable to false deadlocks but better than 1-phase.

Ho-Ramamoorthy 1-phase. Each site keeps two tables — Process Status Table (per process: resources held / waited for) and Resource Status Table (per resource: who holds / wants it). Take a dependency as valid only if BOTH tables agree. Reduces false deadlocks; one collection round vs two.

Chandy-Misra-Haas Edge-Chasing (AND model, distributed). A blocked sends a probe along its outgoing dependency edges. The triple means: = initiator, = sender, = receiver. Probe forwarded from to when is blocked waiting on . **Rule for on receiving probe **: if is blocked AND hasn't already noted dependency on AND hasn't replied to 's requests yet — set . If is deadlocked. Else forward probe to every where is locally dependent on and is waiting on .

Chandy-Misra-Haas complexity. For a deadlock involving sites and processes per site: messages . Single-resource model. Detects deadlock iff a cycle exists in the WFG.

Mitchell-Merritt (single-resource). Each node has a public and private label, initially equal. Block: node sets new private value (unique); public = private. Activate: unblocks. Transmit: blocked node with copies into , propagating 'up' the WFG. Detect: a node receiving back its own public label after a transmit ⇒ deadlock. The node with the highest public label in the cycle detects it.

Mitchell-Merritt key insight. Probes travel OPPOSITE to WFG edges — from waiter back toward holder. Auto-detects cycle when public label propagates around and returns to itself.

Chandy diffusion (OR model). Initiator sends to every in its dependent set. Each blocked , on receiving the *engaging* (first) query for , forwards queries to its own dependent set and waits. Replies propagate back; if the initiator gets replies from all branches it sent queries to ( and ), it declares itself deadlocked.

Algorithm selection by model. Single-resource → Mitchell-Merritt or Ho-Ramamoorthy. AND → Chandy-Misra-Haas probe. OR → Chandy diffusion. AND-OR → repeated OR tests over conjunctive sub-clauses.

Definitions

  • Resource modelsSingle (one pending request); AND (need all); OR (need any one); AND-OR (combination); P-of-Q (any p of q).
  • Wait-For Graph (WFG)Directed graph where nodes = processes and edge means is blocked waiting on .
  • KnotSCC where every node's only reachable nodes are within the SCC (no outgoing edges from the SCC). Deadlock criterion in OR model.
  • Phantom deadlockApparent deadlock detected from a non-atomic WFG snapshot, but never actually existed simultaneously.
  • Chandy-Misra-Haas (CMH) probeEdge-chasing algorithm for AND-model deadlock. Probe travels along WFG edges; deadlock when initiator equals receiver on a returned probe.
  • Mitchell-Merritt algorithmSingle-resource model. Public/private labels at each node; probes propagate OPPOSITE to WFG edges. Deadlock when own public label returns.
  • Chandy diffusion (OR)Diffusion-based detection for OR model. Queries from initiator → dependent set; replies propagate back; deadlock when all branches reply (knot condition).
  • Ho-Ramamoorthy 2-phaseCentralised. Collect process status twice; build WFG from edges appearing in both snapshots. Reduces (but doesn't eliminate) false deadlocks.

Formulas

Derivations

Why OR needs a knot, not a cycle. In the OR model, a process needs ANY ONE of its requested resources. A cycle is insufficient: a process in the 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 guaranteed to be permanently blocked.

CMH probe termination = deadlock. Probe carries . When receives a probe with , it means the probe started at , traversed a path of blocked dependencies, and returned to — proving a cycle in the WFG. Cycle in AND model ⇒ deadlock.

Mitchell-Merritt direction (opposite WFG). WFG edges go waiter → holder. Mitchell-Merritt probes go holder → waiter (along the dependency chain backward). When a node receives its own label, the label has traversed the cycle BACKWARDS — proving cycle existence.

Examples

  • CMH trace on 4-cycle. Processes . blocked, suspects deadlock. Sends probe to . blocked on → sets ; forwards probe to . blocked on → forwards probe. blocked on → forwards probe. receives probe with → deadlock detected. Messages used: 4 for a 4-cycle.
  • Knot example. SCC with edges and NO edges from any of them to anything outside. The SCC is a knot ⇒ all three deadlocked in OR model. Now add (outside-to-inside) and 's only out-edge is is also deadlocked.
  • Mitchell-Merritt label propagation. 3-cycle . Initial labels (1, 1), (1, 1), (1, 1). blocks: label (2, 2). blocks: label (3, 3). sees .public = 3 > 2 → updates to (2, 3). blocks: label (4, 4). sees .public = 4 > 3 → updates to (3, 4). sees .public = 4 → updates to (2, 4). Continue propagating; eventually receives 4 back via , but the highest label in the cycle returns to itself → deadlock.

Diagrams

  • WFG cycle (Single/AND model): 4 processes in a directed cycle ⇒ deadlocked.
  • Knot vs cycle: an SCC inside a graph with outgoing edges (just a cycle, not deadlocked in OR); same SCC without outgoing edges (a knot, deadlocked in OR).
  • CMH probe propagation: 4-cycle with probe → detected.
  • Mitchell-Merritt direction: WFG edges in one direction, probe arrows in the opposite direction.
  • Algorithm-by-model table: rows = Single / AND / OR / AND-OR; cols = best algorithm to use.

Edge cases

  • Phantom deadlock — the WFG changes during collection; the detected cycle never existed in real-time.
  • OR model + just-cycle — not a knot ⇒ NOT deadlocked. Common student error.
  • Detection of deadlock involving site that's just restarted — the new dependencies may be stale.
  • Multiple concurrent initiators in CMH — probes from different initiators can collide; each propagates independently.
  • Mitchell-Merritt label collision — initial values must be unique enough to distinguish cycles; use as label.

Common mistakes

  • Saying 'OR-model deadlock iff cycle'. No — OR needs a KNOT (SCC with no outgoing edges).
  • Confusing probe direction. CMH probes follow WFG edges (waiter → holder). Mitchell-Merritt probes go OPPOSITE.
  • Saying 'Detection is the best because it's always cheap'. No — detection runs ON DEMAND but the algorithm itself may use messages.
  • Forgetting initiator-equals-receiver termination. CMH detects deadlock only when on a probe.
  • Treating Ho-Ramamoorthy as deadlock-free. Still vulnerable to false deadlocks (just less so than naive 1-phase).

Shortcuts

  • Single/AND: cycle ⇒ deadlock. OR: KNOT ⇒ deadlock.
  • CMH probe: = (initiator, sender, receiver). on return ⇒ deadlock.
  • Mitchell-Merritt: probes OPPOSITE WFG; public label returns to self ⇒ deadlock.
  • Chandy diffusion (OR): query + reply waves; reply from all branches ⇒ deadlocked.
  • Detection most popular in DS (vs prevention/avoidance).

Proofs / Algorithms

Knot ⇒ deadlock in OR. A knot is an SCC with no outgoing edges. Every process in the knot waits on someone in the knot (cycle); every wait inside the knot is OR-satisfied only by some resource inside the knot. Since the SCC is a sink, no external resource can free anyone. Hence every process in the knot is permanently blocked.

CMH detects exactly when cycle exists. Cycle ⇒ probe traverses cycle, returns to initiator → detected. No cycle ⇒ probe path is finite (DAG); reaches non-blocked node and stops without returning to initiator.