Deadlock Prevention Strategies
- Process Management
- Memory Management
- Deadlocks
- OS Introduction & Fundamentals
- CPU Scheduling Algorithms
- Threads & Concurrency
- Inter-Process Communication (IPC)
- Process Synchronization
- Virtual Memory & Paging
- File Systems
- Disk Scheduling
- I/O Management
The Core Idea: Break One of the Four Required Conditions
As covered in the previous note, all four conditions - mutual exclusion, hold and wait, no preemption, and circular wait - must hold simultaneously for a deadlock to occur. Deadlock prevention works by designing a system so that at least one of these four conditions can never actually happen.
Attacking Mutual Exclusion
Making resources shareable removes this condition entirely - but many resources (like a printer, or an exclusive write lock) are inherently non-shareable by their very nature, meaning this specific approach only works for resource types that genuinely can be shared safely.
Attacking Hold and Wait
Instead of: request resource 1 -> use it -> request resource 2 -> use it
Require: request ALL needed resources upfront, before starting at allRequiring a process to request every resource it will ever need all at once, before starting, removes the possibility of holding one resource while waiting for another - though this often leads to poor resource utilization, since resources may sit unused for a long time before the process actually needs them.
Attacking No Preemption
Allowing the system to forcibly take a resource away from a process (and give it to another) removes this condition - but this only makes sense for certain resource types, since forcibly interrupting some operations mid-way (like partially written data) can leave things in a genuinely inconsistent state.
Attacking Circular Wait: Ordering All Resources
Assign every resource type a fixed number:
Printer = 1, Disk = 2, Scanner = 3
Rule: a process may only request resources in strictly increasing numeric order.
(this makes a circular waiting chain mathematically impossible to form)Requiring every process to request resources in one single, globally agreed-upon order makes a circular wait mathematically impossible to construct - a widely practical technique, since it doesn't require preemption or giving up hold-and-wait behavior at all.
Why Prevention Isn't Automatically the Best Choice
Every prevention technique trades away some flexibility or resource efficiency to guarantee deadlocks simply cannot happen - which is exactly why deadlock avoidance (covered in the next note) exists as a different, sometimes more practical, approach.