Deadlocks
Dr. Noman Islam
Deadlock condition
1. Mutual exclusion. At least one resource must be held in a nonsharable mode; that is, only one process at a time can use the resource. If another process requests that resource, the requesting process must be delayed until the resource has been released.
2. Hold and wait. A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes.
3. No preemption. Resources cannot be preempted; that is, a resource can be released only voluntarily by the process holding it, after that process has completed its task.
4. Circular wait. A set {P0, P1, ..., Pn} of waiting processes must exist such that P0 is waiting for a resource held by P1, P1 is waiting for a resource held by P2, ..., Pn−1 is waiting for a resource held by Pn, and Pn is waiting for a resource held by P0.
Handling deadlock
Deadlock prevention - Mutual Exclusion
Hold and wait
No preemption
Circular wait
Deadlock avoidance
Safe state
Total resources = 12
Resource Allocation Graph Algorithm
Banker’s algorithm
Data structure required
Safety algorithm
Resource Request algorithm
Deadlock detection
Wait-for graph
Multiple instances of resource
Detection algorithm usage
Recovery from deadlock
Process termination
1. What the priority of the process is
2. How long the process has computed and how much longer the process
will compute before completing its designated task
3. How many and what types of resources the process has used (for example,
whether the resources are simple to preempt)
4. How many more resources the process needs in order to complete
5. How many processes will need to be terminated
6. Whether the process is interactive or batch
Resource preemption