Professional Documents
Culture Documents
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
A set of blocked processes each holding a
resource and waiting to acquire a resource held by
another process in the set.
Example
System has 2 disk drives.
P1 and P2 each hold one disk drive and each needs another one.
P1 P2
R2
R1
Traffic only in one direction.
Each section of a bridge can be viewed as a resource.
If a deadlock occurs, it can be resolved if one car backs up
(preempt resources and rollback).
Starvation is possible.
Resource types are partitioned into several types
CPU cycles, memory space, I/O devices (printers, tape drives) are some
examples of resource types
Mutual exclusion:
Only one process at a time can use a resource.
Circular wait:
There exists a set {P0, P1, , P0} 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, , Pn1 is waiting for a resource that is held by
Pn, and P0 is waiting for a resource that is held by P0.
Deadlock can be represented in terms of directed
graph called System Resource Allocation Graph.
This graph consists of a set of vertices V and a set of edges E.
R = {R1, R2, , Rm}, the set consisting of all resource types in the
system.
Pi requests instance of Rj Pi
Rj
Pi is holding an instance of Rj Pi
Rj
If graph contains no cycles no deadlock.
Deadlock
Prevention Deadlock
Avoidance Deadlock
Detection Deadlock
Recovery
Prevention
Ensure that the system will never enter a deadlock
state
Avoidance
Ensure that the system will never enter an unsafe
state
Detection and Recovery
Allow the system to enter a deadlock state and then
recover
This method is preferable when deadlocks happen
rarely
For deadlock to occur, each of the four conditions must hold. So in
order to prevent the occurrence of deadlock we assume that at least
one of the condition cannot hold.
Simplest and most useful model requires that each process declare the
maximum number of resources of each type that it may need.
Detection algorithm
Recovery scheme
Maintain wait-for graph
Nodes are processes.
Pi Pj if Pi is waiting for Pj.
Process Process
Termination Preemption
Abort all deadlocked processes.
Rollback return to some safe state, restart process for that state.