3. Deadlock Avoidance
Deadlock avoidance is a technique used to avoid
deadlock.
It requires information about how different processes
would request different resources.
Safe state: if deadlock not occur then safe state.
Unsafe state: if deadlock occur then unsafe state.
The idea of avoiding a deadlock is simply not allow the
system to enter an unsafe state the may cause a
deadlock.
4. Resource Allocation Graph
Algorithim
Claim edge: used to indicate that process may request a
resource in future..
It represented by dashed lined.
Claim edge converts to Assignment edge when a process
requests a resource.
Assignment Edge is represented by solid line.
When a resource is released by a process, assignment edge
reconverts to a claim edge.
7. Banker’s Alghorithum
Multiple instances.
Each process must a priori claim maximum use.
When a process requests a resource it may have to
wait.
When a process gets all its resources it must return
them in a finite amount of time.
8. Example Banker’s Algorithm
Example: If we
Process A B C D
P1 2 0 1 1
P2 0 1 0 0
P3 1 0 1 1
P4 1 1 0 1
Allocation Matrix
Available
resource(5,2,4,3)
Allocation resources
(4,2,2,3)
10. Solve the Example
Available free resources=Available resource –Allocated
resources
Available free resources=(5,2,4,3)-(4,2,2,3)
Available free resources=(1,0,2,0)
Working of Banker’s Algorithm:
Need Resources <=Available free Resources(when
the condition is satisfied then processes in safe state
otherwise not.)
For p1: (1,1,0,0)<=(1,0,2,0)
Unsafe state (not Available)
11. Continue………
For p2: (0,1,1,2)<=(1,0,2,0)
Unsafe(Not Available)
For p3: (3,,1,0,0)<=(1,0,2,0)
Unsafe(Not Available)
For p4: (0,,0,1,0)<=(1,0,2,0)
(Available) Safe
Now the process p4 complete, it will turn over currently
allocated resources ,incrementing the available free
resources..
12. Updated value of Available Resource=Current
value of available Resources + Allocated resources
of Allocated matrix
Need process(p1)=(1,1,0,0)<=(2,1,2,1) Available
Now p1 is complete, it will turn over currently allocated
resources ,incrementing the available free resources..
(1.1,0,1) Allocation of process(p4)
(2,1,2,1) updated value of Available
13. (2,1,2,1) Current value of Available
(2,0,1,1) Allocation process (P1)
(4,1,3,2) Updated value of Available