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

Deadlock Avoidance: Banker's Algorithm

College Depth 109 in the knowledge graph ☐ I know this ☆ Set as goal
425prerequisites beneath it
See this on the map →
Deadlock Conditions and Resource GraphsDeadlock Prevention and Avoidance Strategies→
deadlock avoidance banker

Core Idea

Banker's algorithm grants resource requests only if the resulting state is safe (all processes can eventually finish). It uses maximum claims and simulates allocation; though expensive, it prevents deadlock without breaking any condition or blocking any progress.

Explainer

From your study of deadlock conditions and prevention, you know the four necessary conditions for deadlock (mutual exclusion, hold-and-wait, no preemption, circular wait) and that prevention works by structurally eliminating one of them — for example, requiring processes to request all resources upfront eliminates hold-and-wait. Prevention is conservative: it restricts what processes can do even when no deadlock threat exists. Deadlock avoidance takes a different approach — it allows processes to request resources freely but refuses any request that would put the system into an unsafe state.

The Banker's Algorithm, named by analogy to a cautious banker who never lends out so much cash that remaining customers cannot be satisfied, requires one key piece of information upfront: the maximum claim of each process — the most of each resource type it will ever need simultaneously. At any moment, the system knows how many resources are allocated to each process, how many each process might still request (maximum claim minus current allocation), and how many resources remain available. A state is safe if there exists some ordering of processes such that each process can obtain its maximum remaining needs from the currently available resources plus the resources that will be released by processes that finish before it.

Here is a concrete example. Suppose there are 12 units of a single resource and three processes: P1 holds 5 (max 10), P2 holds 2 (max 4), P3 holds 2 (max 9). Available = 12 - 5 - 2 - 2 = 3. Is this safe? P2 needs at most 2 more, and 3 are available, so P2 can finish. After P2 finishes, available = 3 + 2 = 5. Now P1 needs at most 5 more, and 5 are available, so P1 can finish. After P1 finishes, available = 5 + 5 = 10. P3 needs at most 7 more, and 10 are available, so P3 can finish. The safe sequence is <P2, P1, P3>. If P1 now requests 1 more unit, the system would have available = 2. Can we still find a safe sequence? P2 can finish (needs 2, has 2), releasing to available = 4. P1 now holds 6, needs 4 more, and 4 are available — P1 can finish. Then P3 finishes. So the request is granted. If instead P3 requests 1 more, available drops to 2: P2 finishes (available = 4), but P1 needs 5 and P3 needs 7 — neither can finish with 4. No safe sequence exists, so the request is denied.

The algorithm runs this simulation on every resource request, which means its complexity is O(n² × m) where n is the number of processes and m the number of resource types. In practice this is too expensive for general-purpose operating systems with thousands of processes and resources, and the requirement that processes declare maximum claims upfront is often unrealistic. But the Banker's Algorithm is foundational as a conceptual model: it precisely defines what "safe state" means and demonstrates that deadlock can be avoided without restricting how processes use resources, as long as the system has enough information to reason about the future.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Process Creation: fork() and exec() → Process Termination and Resource Cleanup → Process States and State Transitions → Process Model Formalization → Context Switching and CPU Dispatch → CPU Scheduling Fundamentals → Round-Robin (RR) Scheduling → First-Come-First-Served (FCFS) Scheduling → Scheduling Fairness and Starvation Prevention → Thread Scheduling and Coordination → Semaphores → Deadlock: Conditions and Modeling → Deadlock Conditions and Resource Graphs → Deadlock Detection and Recovery → Deadlock Prevention and Avoidance Strategies → Deadlock Avoidance: Banker's Algorithm

Longest path: 110 steps · 425 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.