Operating Systems · Deadlock Avoidance and Banker's Algorithm
Deadlock Prevention by Disabling Necessary Conditions
Overview
Deadlock handling can be approached either by reacting after a deadlock occurs or by designing the system so that deadlock can never occur.
Deadlock prevention belongs to the second, proactive approach: it disables the conditions that make deadlock possible, following the principle "prevention is better than cure."
Key concepts
- Deadlock ignorance: a method of handling deadlock by shutting down the system and restarting it when deadlock occurs.
- Deadlock prevention: a method in which the system is designed so that deadlock can never occur in the first place — "prevention is better than cure."
- Four necessary conditions for deadlock: deadlock exists only if all four necessary conditions hold.
- Disabling conditions: to prevent deadlock, disable all the necessary conditions or disable at least one of them. Disabling at least one necessary condition is sufficient to guarantee that deadlock cannot occur.
- No recovery needed: if deadlock cannot occur, there is no need to deal with deadlock recovery or handling at all.
- Deadlock avoidance: the next category of deadlock handling after prevention; prevention is proactive, avoidance follows it.
How it works
- Deadlock ignorance: if a deadlock occurs, the system is shut down and restarted.
- Deadlock prevention goal: ensure that deadlock will never occur in the system in the first place; if deadlock never occurs, there is no need to deal with it at all.
- Achieving prevention: identify the four necessary conditions for deadlock, then disable all of them or disable at least one of them.
- Guarantee: if at least one necessary condition is disabled, deadlock will definitely never happen.
Drawing the diagram…
Comparison
| Method | Approach | Action |
|---|---|---|
| Deadlock ignorance | Reactive | Shut down and restart the system when deadlock occurs |
| Deadlock prevention | Proactive | Design the system so deadlock can never occur by disabling all or at least one of the four necessary conditions |
Revision summary
- Deadlock ignorance = shut down and restart the system.
- Deadlock prevention = make sure deadlock never occurs.
- Deadlock exists only if all four necessary conditions hold; therefore breaking at least one condition prevents deadlock.
- Disabling at least one necessary condition is sufficient to guarantee that deadlock cannot occur.
- If deadlock cannot occur, no deadlock recovery or handling is needed.
- Prevention is proactive; avoidance is the next category of handling deadlock.
Previous-year exam insights
- The four necessary (Coffman) conditions for deadlock are mutual exclusion, hold and wait, no preemption, and circular wait; deadlock prevention works by ensuring at least one of these can never hold.
Asked inGATE 2015GATE 2000 - Standard prevention schemes: (1) mutual exclusion — make resources sharable where possible (e.g., spooling); (2) hold and wait — require a process to request all resources at once before execution, or release all held resources before requesting more; (3) no preemption — preempt (forcefully take) resources from a waiting process; (4) circular wait — impose a total ordering on resources and require requests in strictly increasing order.
Asked inGATE 2015GATE 2000 - Deadlock prevention is static and conservative: it restricts how requests may be made so that deadlock is structurally impossible, and it does not consider the current state; deadlock avoidance is dynamic and grants a request only if the resulting state is safe, which requires advance knowledge of each process's maximum resource needs.
Asked inGATE 2008ISRO 2017 - In deadlock avoidance a request is granted only when the resulting state is safe (not merely when resources are free), whereas in prevention requests are granted according to the imposed protocol regardless of safety; hence prevention is more restrictive than avoidance.
Asked inGATE 2008ISRO 2017 - A scheme that releases all held resources before requesting new ones does break hold-and-wait and is a valid prevention scheme; a scheme that merely never requests a resource after releasing any resource does not break any necessary condition and is not a valid prevention scheme.
Asked inGATE 2000 - Resource numbering (requesting only in increasing order of resource numbers) breaks the circular-wait condition, so it is a valid prevention technique.
Asked inGATE 2015GATE 2000