Saral Shiksha Yojna
Courses/Distributed Systems

Distributed Systems

CS3.401
Prof. Kishore KothapalliMonsoon 2025-264 credits

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

NotesStoryCaveman
Unit 6 — Distributed Deadlock Detection

Whole tribe freeze by the fire, nobody move

Ugg tell you the worst thing: the tribe FREEZE. Every hunter grip one rock and want the rock the next hunter holds. Nobody let go. Nobody hunt. Everyone starve. That is deadlock — a ring of hunters, each waiting on a thing the next one clutches.

In one cave, easy to spot. But a distributed system is many caves across the valley — no single cave sees all the hunters. To see the whole ring, caves must shout messages, and while they shout, hunters move and the picture changes. THAT is why the freeze is hard to catch here.

How many rocks make a hunter happy — resource models

The resource request models say what a hunter needs before he moves:

  • Single resource — waits for at most one rock at a time.
  • AND model — needs ALL his rocks together, or he stays frozen.
  • OR model — needs ANY ONE rock of many. Give him one, he happy.
  • AND-OR model — a mix, like : need X, and need Y or Z.
  • P-out-of-Q — needs any rocks out of the he asked for.

This matters: how you SPOT the freeze changes with the model.

The footprint map — Wait-For Graph

Draw the map. Each hunter a dot. Draw an arrow when sits blocked waiting on . This is the Wait-For Graph (WFG) — arrows point from waiter TO holder, footprints of who waits for who.

Ring versus knot — do NOT mix these up

Biggest lesson by the fire.

In single and AND models, if the footprints loop back on themselves — a cycle — the tribe is frozen. Done.

OR is sneaky. A loop is NOT enough! A hunter in the loop might ALSO wait on a rock OUTSIDE it, and needing only ONE rock, that outside rock could free him and snap the ring. Only when the loop has NO arrow leaving it — a knot — is everyone truly stuck.

A knot is a strongly connected component (SCC) — a clump where every dot reaches every other dot — that has NO outgoing arrow (a sink). Inside, every wait can only be fed from inside, and nothing leaves, so nobody ever gets fed. Frozen forever. Ugg warn: NEVER say "OR freezes on a cycle." WRONG — OR freezes on a KNOT. A hunter outside whose every path leads only inward is stuck too.

Three ways the tribe fights freeze

  • Prevention — build rules so freeze can't happen (everyone grabs rocks in one fixed order). Slow; some hunters starve.
  • Avoidance — check before handing a rock, Banker-style. Needs the WHOLE valley's state. Too costly far apart.
  • Detection — let freeze happen, then go LOOK, then break it. The FAVORITE in distributed land — the other two need expensive whole-valley knowledge.

Once found, break it three ways: process termination (kill a hunter in the ring), resource preemption (rip a rock from his hand), or rollback (send him back to an old safe spot).

Who does the looking — control organisations

  • Centralised — one chief builds the whole map. Chief dies, all go blind: single point of failure.
  • Distributed — every cave shares the job with waves and probes.
  • Hierarchical — caves in a family tree; the nearest shared ancestor-cave checks.

Ghost freeze — phantom deadlock

Ugg warn of ghosts! Caves gather footprints SLOWLY, so the map shifts while you draw it. A hunter drops his rock and walks off, but your half-drawn map still shows him waiting. You "see" a ring that never stood at one moment. That is a phantom deadlock, a false freeze.

The Ho-Ramamoorthy chief-method fights ghosts. Its 2-phase way collects every cave's status TWICE and keeps only footprints seen BOTH times. Its 1-phase way keeps two tally-sticks per cave — a Process Status Table (what each hunter holds and wants) and a Resource Status Table (who holds and wants each rock) — and trusts a footprint only when BOTH sticks agree. Ugg warn: this thins ghosts but does NOT kill them all.

The pebble chase — Chandy-Misra-Haas (AND)

Hunt-trick for AND, called Chandy-Misra-Haas edge-chasing. A blocked hunter throws a probe — a marked pebble carrying three names:

threw it first, throws it now, catches it. The pebble travels ALONG the arrows (waiter to holder). A blocked who catches it marks the dependency and throws it on to whoever HE waits for. The magic:

If the pebble returns to the hunter who first threw it, the ring is real — FREEZE. Ugg warn: ONLY counts.

Watch the ring . throws probe ; it becomes , then , then lands back on with — freeze, in 4 pebbles. Cost stays small:

for caves and hunters each. Ugg warn: detection runs only on demand, but the run itself STILL throws many pebbles — it is NOT free.

The label climb — Mitchell-Merritt (single)

For single-resource, use Mitchell-Merritt. Each hunter carries two shiny stones — a public label and a private label, equal at start. On block, he carves a fresh unique number onto both. When a blocked hunter points at and sees 's public number is BIGGER, copies it onto his own public stone. Big numbers climb the chain.

The key: these labels crawl OPPOSITE to the WFG arrows — the waiter copies the bigger label off the hunter he waits ON, so numbers climb backward along the chain (holder toward waiter). When a hunter gets his OWN public number handed back, it went all the way around the ring — FREEZE — and the hunter with the biggest number spots it. Ugg warn: do NOT mix directions — CMH pebbles go ALONG arrows, Mitchell-Merritt labels go OPPOSITE.

The wave — Chandy diffusion (OR)

For OR, use Chandy diffusion. The initiator sends a wave to every hunter in its waiting-set. Each blocked hunter, on the FIRST (engaging) query, passes the wave onward and waits. Replies wash back; when the initiator gets replies from ALL branches it sent to ( with ), it sits in a knot — frozen.

Match trick to model — the cheat-stone

  • Single resource → Mitchell-Merritt or Ho-Ramamoorthy.
  • AND → Chandy-Misra-Haas probe.
  • OR → Chandy diffusion.
  • AND-OR → run the OR test again and again over each AND-piece.

Ugg remember

  • Cycle freezes single/AND. A knot — an SCC with NO arrow out — freezes OR. A bare cycle in OR is NOT a freeze.
  • CMH probe = initiator, sender, receiver; travels ALONG arrows; back home ⇒ freeze; cost .
  • Mitchell-Merritt labels crawl OPPOSITE the arrows; your own public label returning ⇒ freeze. Opposite direction from CMH!
  • Detection is the DS favorite (prevention and avoidance need whole-valley state), but it is not free and can be fooled by phantom ghost-freezes.
  • Match trick to model: single → Mitchell-Merritt, AND → CMH probe, OR → Chandy diffusion.
End of storyUnit 6 — Distributed Deadlock Detection · Resource Models, WFG, CMH Probe, Mitchell-Merritt, Chandy Diffusion