A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Deadlock: Conditions and Modeling

College Depth 105 in the knowledge graph I know this Set as goal
5topics build on this
412prerequisites beneath it
See this on the map →
Mutual Exclusion and LocksSemaphoresDeadlock Conditions and Resource GraphsDeadlocks in Databases
deadlock Coffman-conditions resource-allocation-graph circular-wait

Core Idea

A deadlock is a state where a set of processes are each waiting for a resource held by another process in the set, and none can proceed. Coffman et al. identified four necessary conditions that must all hold simultaneously for deadlock to occur: mutual exclusion (resources are non-shareable), hold and wait (a process holds resources while waiting for more), no preemption (resources cannot be forcibly taken), and circular wait (a circular chain of processes exists, each waiting for the next). Resource-Allocation Graphs (RAGs) are the standard formal tool for detecting deadlocks: a cycle in the RAG is a necessary condition for deadlock, and sufficient when each resource type has exactly one instance.

How It's Best Learned

Draw the dining philosophers problem as a resource-allocation graph with five philosophers and five forks. Show how a cycle forms if all five pick up their left fork simultaneously.

Common Misconceptions

Explainer

From your work on mutexes and locks, you know that threads must acquire exclusive access to shared resources to avoid race conditions. Deadlock is the dark side of that protection: when multiple threads each hold a resource and wait for another resource held by a different thread, the system can reach a state where nobody can make progress. Imagine two people in a narrow hallway, each refusing to step aside — neither can pass, and both wait forever.

The four Coffman conditions provide a precise framework for understanding when deadlocks can occur. All four must hold simultaneously. Mutual exclusion means at least one resource is non-shareable — only one thread can use it at a time (this is the nature of a mutex). Hold and wait means a thread holds at least one resource while waiting to acquire another. No preemption means resources cannot be forcibly taken from a thread — the thread must release them voluntarily. Circular wait means there is a cycle of threads, each waiting for a resource held by the next thread in the chain. The classic illustration is the dining philosophers problem: five philosophers sit at a round table, each needing two forks to eat. If all five pick up their left fork simultaneously, each holds one fork and waits for the right fork held by their neighbor — all four conditions hold, and nobody eats.

The Resource-Allocation Graph (RAG) is the formal tool for modeling and detecting deadlocks. It is a directed graph with two types of nodes: processes (circles) and resource types (rectangles with dots representing instances). A request edge goes from a process to a resource it is waiting for. An assignment edge goes from a resource instance to the process holding it. If you draw the RAG for a system and find a cycle, that indicates a potential deadlock. For single-instance resource types (one printer, one database lock), a cycle is both necessary and sufficient for deadlock — the cycle *is* the deadlock. For multi-instance resource types (three identical printers), a cycle is necessary but not sufficient: the cycle might resolve if one thread finishes and releases an instance, allowing another thread in the cycle to proceed.

The practical power of the Coffman conditions is that eliminating any one of the four prevents deadlock entirely. Most real systems attack circular wait by imposing a total ordering on resources: all threads must acquire resources in the same global order (e.g., always lock A before lock B). If every thread follows this order, a circular chain cannot form. Other strategies include disallowing hold-and-wait (a thread must request all resources upfront), allowing preemption (if a thread cannot get what it needs, it releases what it holds), or avoiding mutual exclusion where possible (using read-write locks instead of exclusive locks). Each strategy has tradeoffs in complexity and performance, but the key insight is structural: deadlock is not random bad luck — it requires all four conditions, and you can engineer systems to break at least one.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsLogic Gates FundamentalsImplementing Boolean Functions with GatesKarnaugh Map SimplificationCombinational Circuit DesignFlip-Flops and LatchesBinary Counters: Design and AnalysisBinary ArithmeticFixed-Point Number RepresentationTwo's Complement RepresentationOverflow and Underflow DetectionBinary Adders: Half-Adders and Full-AddersFull Adder and Carry PropagationCarry Lookahead Adder DesignHalf Adder Circuit DesignMultiplication Circuit DesignSequential Circuit DesignRegisters and Register FilesInstruction Set Architecture (ISA)Kernel Architecture and OS StructureSystem Calls and User/Kernel ModeProcesses and the Process Control BlockProcess Creation: fork() and exec()Process Termination and Resource CleanupProcess States and State TransitionsProcess Model FormalizationContext Switching and CPU DispatchCPU Scheduling FundamentalsRound-Robin (RR) SchedulingFirst-Come-First-Served (FCFS) SchedulingScheduling Fairness and Starvation PreventionThread Scheduling and CoordinationSemaphoresDeadlock: Conditions and Modeling

Longest path: 106 steps · 412 total prerequisite topics

Prerequisites (2)

Leads To (2)