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 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 ModelingDeadlock Conditions and Resource GraphsDeadlock Detection and RecoveryDeadlock Prevention and Avoidance StrategiesDeadlock Avoidance: Banker's Algorithm

Longest path: 110 steps · 425 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.