Deadlock Conditions and Resource Graphs

College Depth 71 in the knowledge graph I know this Set as goal
Unlocks 3 downstream topics
deadlock conditions graphs

Core Idea

Deadlock requires all four conditions: mutual exclusion, hold-and-wait, no preemption, and circular wait. Resource allocation graphs visualize these conditions; a cycle indicates potential deadlock. Understanding which condition to break guides prevention and recovery strategies.

How It's Best Learned

Construct resource graphs for various scenarios; identify cycles and trace the circular-wait pattern.

Common Misconceptions

Explainer

From your study of deadlock conditions, you know the four requirements: mutual exclusion, hold-and-wait, no preemption, and circular wait. You may also have encountered the dining philosophers problem, which illustrates how circular resource dependencies arise naturally. This topic formalizes these ideas by introducing a visual and analytical tool — the resource allocation graph — and examines how the four conditions interact in practice.

A resource allocation graph is a directed graph with two types of nodes: processes (drawn as circles) and resource types (drawn as rectangles, with dots inside representing instances). Two types of edges exist: a request edge goes from a process to a resource (meaning the process is waiting for that resource), and an assignment edge goes from a resource to a process (meaning that instance is currently held by that process). To check for deadlock, you look for cycles in this graph. If every resource type has exactly one instance, a cycle means deadlock is guaranteed — the processes in the cycle are all waiting for resources held by the next process in the cycle, and none can proceed. If resource types have multiple instances, a cycle is necessary but not sufficient: deadlock is possible but not certain, because another instance might become available.

Consider a concrete example with three processes and three resources. Process A holds Resource 1 and requests Resource 2. Process B holds Resource 2 and requests Resource 3. Process C holds Resource 3 and requests Resource 1. Drawing the graph reveals a clear cycle: A → R2 → B → R3 → C → R1 → A. Each process holds one resource and waits for another, and the waiting chain forms a loop. All four conditions are present: each resource allows only one holder (mutual exclusion), each process holds one resource while requesting another (hold-and-wait), the OS cannot forcibly take resources away (no preemption), and the cycle completes the circular wait. Remove any one condition and the deadlock breaks — for instance, if Process A could be preempted and its resource forcibly reassigned, the cycle breaks.

This framework guides practical deadlock strategies. Prevention eliminates one of the four conditions by design — for example, requiring processes to request all resources at once (eliminating hold-and-wait) or imposing a global ordering on resource acquisition (eliminating circular wait). Detection periodically constructs the resource allocation graph and runs a cycle-detection algorithm; if a cycle is found, the system kills or rolls back one of the processes involved. Avoidance (which you'll study next with the Banker's Algorithm) uses the graph proactively, refusing resource grants that *could* lead to a cycle. The graph formalism turns an abstract concurrency problem into a concrete data structure problem: deadlock detection is just cycle detection in a directed graph, a problem you can solve in O(V + E) time using depth-first search.

Practice Questions 5 questions

Prerequisite Chain

Counting to 10Counting to 20Understanding ZeroThe Number ZeroCounting to FiveOne-to-One CorrespondenceCombining Small Groups Within 5Addition Within 10Addition Within 20Two-Digit Addition Without RegroupingTwo-Digit Addition with RegroupingAddition Within 100Repeated Addition as MultiplicationMultiplication 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 100Two-Digit by One-Digit DivisionDivision with RemaindersRemainders and Quotients in DivisionDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueReading and Writing DecimalsComparing and Ordering DecimalsAdding and Subtracting DecimalsMultiplying DecimalsDividing DecimalsDividing FractionsMixed Number ArithmeticOrder of OperationsOperators and ExpressionsArithmetic Operators and Operator PrecedenceComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsCombinational 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 TransitionsThreads and ConcurrencyThe Critical Section Problem and Race ConditionsMutual Exclusion and LocksSemaphoresDeadlock: Conditions and ModelingDeadlock Conditions and Resource Graphs

Longest path: 72 steps · 261 total prerequisite topics

Prerequisites (2)

Leads To (3)