Deadlock Avoidance

·         Provide information to OS that which all resources any process will require during its lifetime.

·         Then at every request the system can decide whether to grant that request or not.

·         This decision depends upon 

ü  resources currently available

ü  resources currently allocated to each process

ü  future request and release of resources by each process

Safe State: state is safe if the system can allocate resources to every process in some order and still avoid deadlock. 

Safe sequence – is an order {P1, P2, … Pn} in which the processes can be allocated resources safely.

NOTE:  

·         Safe state – No deadlock

·         Unsafe State - Deadlock may or may not occur 

Conclusion

·         Do not grant the request immediately

·         Check whether granting the request will leave the system in safe state or not?

·         If yes, grant the request

·         If no, do not grant the request

Disadvantage

·         Low resource utilization

Algorithms for deadlock avoidance

·         Resource allocation graph algorithm

·         Banker’s algorithm

Resource Allocation graph - this technique can be  employed when there is single instance of every resource. In resource allocation graph for deadlock avoidance we introduce a third kind of edge called the claim edge which is a dotted line from a process towards a resource meaning that the resource can be requested by the process in future.
Whenever  a process requests for a resource the claim edge is changed to request edge and if the resource can be granted the request edge is changed to assignment edge. After this change look for a cycle in the graph. If no cycle exists, then the system is in safe state and the deadlock will not occur else the  system is in unsafe state and deadlock may or may not occur.


Banker's Algorithm - this technique is used when there are multiple instances of a resource. This algorithm requires four data structures to be implemented:

·         Available – no. of available resources of each type

·         Max – maximum need of any process for any resource

·         Allocation – number of resources allocated to each process

·         Need – (Max – Allocation)