Skip to content
Preptima
easyConceptCodingEntry

State the four conditions for deadlock, then show me how you would stop a real program from deadlocking.

Deadlock needs all four Coffman conditions at once: mutual exclusion, hold and wait, no preemption and circular wait. Breaking any one prevents it, and the practical choice is usually circular wait, by making every thread take locks in one global order.

4 min readUpdated 2026-10-10Target archetype: Enterprise Captive

Answer

Short answer

Deadlock happens only when four conditions hold at the same time, usually called the Coffman conditions. They are mutual exclusion, hold and wait, no preemption, and circular wait. Because all four are needed, breaking any one prevents it. In real programs you nearly always break circular wait, by making every thread acquire locks in one agreed global order.

Was this answer helpful?

Likely follow-ups

  • Philosopher 4 now picks up fork 0 first. Trace why no cycle can form with five philosophers.
  • Why can mutual exclusion almost never be removed for a lock protecting a counter?
  • A resource-allocation graph has a cycle but each resource type has two instances. Is the system deadlocked?
  • What information does the Banker's algorithm need up front, and why do general-purpose systems rarely have it?

Related questions