Make sure atleast one of the 4 deadlock conditions is never satisfied.
This may however be even more conservative than deadlock avoidance strategy.
Resources numbered 1 ... n. Resources can be requested only in increasing order. ie. you cannot request a resource whose no is less than any you may be holding.
Think of it as a state machine moving from 1 state to another as each instruction is executed.
Safe StateSafe state is one where
To avoid deadlocks, we try to make only those transitions that will take you from one safe state to another. We avoid transitions to unsafe state (a state that is not deadlocked, and is not safe) eg.
Total # of instances of resource = 12
(Max, Allocated, Still Needs)
P0 (10, 5, 5) P1 (4, 2, 2) P2 (9, 2, 7) Free = 3 - Safe
The sequence is a reducible sequence
the first state is safe.
What if P2 requests 1 more and is allocated 1 more instance?
- results in Unsafe state
So do not allow P2's request to be satisfied.
Banker's Algorithm for Deadlock AvoidanceWhen a request is made, check to see if after the request is satisfied, there is a (atleast one!) sequence of moves that can satisfy all the requests. ie. the new state is safe. If so, satisfy the request, else make the request wait.
How do you find if a state is safen process and m resourcesMax[n * m]
Allocated[n * m]
Still_Needs[n * m]
Available[m]
Temp[m]
Done[n]
while () {
Temp[j]=Available[j] for all j
Find an i such that
a) Done[i] = False
b) Still_Needs[i,j] <= Temp[j]
if so {
Temp[j] += Allocated[i,j] for all j
Done[i] = TRUE}
}
else if Done[i] = TRUE for all i then state is safe
else state is unsafe
}
Detection and RecoveryIs there a deadlock currently?One resource of each type (1 printer, 1 plotter, 1 terminal etc.)
Multiple resources of each type
Check R matrix, and find a row i such at Ri < A.
If such a process is found, add Ci to A and remove process i from the system.
Keep doing this till either you have removed all processes, or you cannot remove any other process.
Whatever is remaining is deadlocked.
Basic idea, is that there is atleast 1 execution which will undeadlock the system
Copyright © 2026 eLLeNow.com All Rights Reserved.