Chapter 7: Deadlocks
No preemption (deadlock prevention)
- If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released -Preempted resources are added to the list of resources for which the process is waiting -Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting
how to recover from a deadlock when using process termination
- abort all deadlocked processes - abort one process at a time until deadlock cycle is eliminated
Deadlock Detection for single instance of each resource type
- maintain a wait-for graph - Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock - An algorithm to detect a cycle in a graph requires an order of nsquared operations, where n is the number of vertices in the graph
recover from deadlock using resource preemption
- select a victim - minimize cost - roll back - return to some safe state restart process for that state
Deadlock avoidance
-Requires that the system has some additional a priori information available - 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
Deadlock Avoidance Pro
Avoids deadlock and is less restrictive than deadlock prevention
For shareable resources, is mutual exclusion required?
No, it is not required so hence cannot be involved in a deadlock
Deadlock Prevention
Restrain the ways requests can be made
How to use deadlock avoidance when there is a single instance?
Single instance -> use resource allocation graph
safe state
System is in safe state if there exists a sequence of ALL the processes in the systems such that for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < i ,>
Hold and wait
a process holding at least one resource is waiting to acquire additional resources held by other processes
claim edge converts to request edge when...
a process requests a resource
no preemption
a resource can be released only voluntarily by the process holding it, after that process has completed its task
Bankers Algorithm
applicable when there are multiple instances of each fresource type 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
when a resource is released by a process..
assignment edge reconverts to a claim edge
If the wait for graph contains a cycle : a) then a deadlock does not exist b) then a deadlock exists c) then the system is in a safe state d) either b or c
b) then a deadlock exists
if a graph contains a cycle with one instance per resource type...
deadlock occurs
methods for handling a deadlock
deadlock prevention & avoidance Allow the system to enter a deadlock state and then recover Ignore the problem and pretend that deadlocks never occur in the system
Detection-algorithm issues
dont know when, and how often to invoke if invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes "caused" the deadlock.
Circuit wait (deadlock prevention)
impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration
Drawbacks of Bankers Algorithm
in advance processes rarely know that how much resource they will need the number of processes changes as time progresses resource once available can disappear
How to use deadlock avoidance when there are multiple instances?
multiple instances -> use bankers algorithm
hold and wait (deadlock prevention)
must guarantee that whenever a process requests a resource, it does not hold any other resources Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none allocated to it. Low resource utilization; starvation possible
Deadlock Characterization
mutual exclusion , hold and wait, no preemption, circular wait
If a graph contains no cycles..
no deadlock
if system is in safe state
no deadlocks
Mutual exclusion (Deadlock Prevention)
not required for sharable resources (e.g., read-only files); must hold for non-sharable resources
Mutual Exclusion
only one process at a time can use a resource
Deadlock Avoidance Con
only works with a fixed number of resources and processes
if system is in unsafe state
possibility of a dealock
if a graph contains a cycle with several instances per resource type...
possibility of deadlock
Each process utilizes a resource as follows:
request, use, release
when using a resource allocation graph scheme
resources must be claimed a priori
Deadlock recovery con
starvation- the same process may always be picked as a victim, include number of rollback in cost factor
request edge converts to an assignment edge when...
the resource is allocated to the process
circular wait
there exists a set {P0, P1, ..., Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, ..., Pn-1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0.
How to ensure a system will never enter a deadlock state?
use deadlock prevention and deadlock avoidance