Home | Projects | Notes > Operating Systems > Deadlock Avoidance
Unlike deadlock prevention, deadlock avoidance allows the three necessary conditions but makes judicious choices to assure that the deadlock point is never reached.
A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock
Requires knowledge of future process requests!
Two approaches to deadlock avoidance:
Process initiation denial - Do not start a process if its demands might lead to deadlock.
Process allocation Denial (Banker's algorithm) - Do not grant an incremental resource request to a process if this allocation might lead to deadlock.
Do not start a process if its demands might lead to deadlock. (Too strict, no incremental work done)
Consider a system of
Resource - total amount of each resource in the system
Available - total amount of each resource not allocated to any process
Claim -
Claim matrix must be declared in advance by a process for deadlock avoidance to work.
Allocation -
The following relationships hold:
All resources are either available for allocated.
No process can claim more than the total amount of resources in the system.
No process is allocated more resources of any type than the process originally claimed to need.
With these quantities defined, we can define a deadlock avoidance policy that refuses to start a new process if its resource requirements might lead to deadlock. Start a new process
That is, a process is only started if the maximum claim of all current processes plus those of the new process can be met. This strategy is hardly optimal, because it assumes the worst: that all processes will make their maximum claims together.
Do not grant an incremental resource request to a process if this allocation might lead to deadlock.
Consider a system with a fixed number of processes and a fixed number of resources. At any time a process may have zero or more resources allocated to it.
Here, two vectors and two matrices that were used in "Process Initiation Denial" approach are used as well.
Vectors - Resource (
Matrices - Claim (
State of the system - reflects the current allocation of resources to processes.
Safe state - there is at least one sequence of resource allocations to processes that does not result in a deadlock (i.e., all of the processes can be run to completion).
Unsafe state - state that is not safe.
Can any of the process be run to completion with the resources available? Does the process
When a process makes a request for a set of resources, assume the request is granted, update the system state accordingly, then determine if the result is a safe state. If so, grant the request and, if not, block the process until it is safe to grant the request.
Determination of an unsafe state
Determination of a safe state
It is not necessary to preempt and rollback processes as in deadlock detection.
Less restrictive than deadlock prevention.
The maximum resource requirement for each process must be stated in advance.
The processes under consideration must be independent; that is, the order in which they execute must be unconstrained by any synchronization requirements.
There must be a fixed number of resources to allocate.
No process may exit while holding resources.
Stallings, W. (2018). Operating Systems: Internals and Design Principles (9th ed.). Pearson Education, Inc.