Deadlock avoidance approach requires that the system has some additional a priori information available. The simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need. The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition. Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.
Safe state
A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock. When a process requests an available resource, the system must decide if immediate allocation leaves the system in a safe state.
System is in safe state if there exists a sequence
P1,
P2, ...,
Pn
of all the processes such that for each
Pi, the resources that
Pi can still request can be satisfied by currently available resources plus resources held by all the
Pj, with
j
i. If no such sequence exists, then the system state is said to be unsafe. Not all unsafe states are deadlocks but an unsafe state may lead to a deadlock.
Resource-allocation graph algorithm
The resource-allocation graph has request and assignment edges. In addition, there is a claim edge. The claim edge
Pi –›
Rj indicated that process
Pj may request resource
Rj and it is represented by a dashed line. Claim edge converts to request edge when a process requests a resource. Request edge converted to an assignment edge when the resource is allocated to the process. When a resource is released by a...