2. 7.2
Deadlocks
โ The Deadlock Problem
โ System Model
โ Deadlock Characterization
โ Methods for Handling Deadlocks
โ Deadlock Prevention
โ Deadlock Avoidance
โ Deadlock Detection
โ Recovery from Deadlock
3. 7.3
Chapter Objectives
โ To develop a description of deadlocks, which
prevent sets of concurrent processes from
completing their tasks
โ To present a number of different methods for
preventing or avoiding deadlocks in a computer
system
4. 7.4
The Deadlock Problem
โ 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 holds one disk drive and each needs
another one
โ Example
โ semaphores A and B, initialized to 1
P0 P1
wait (A); wait(B)
wait (B); wait(A)
5. 7.5
Bridge Crossing Example
โ 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)
โ Several cars may have to be backed up if a deadlock
occurs
โ Starvation is possible
โ Note โ Most OSes do not prevent or deal with deadlocks
6. 7.6
System Model
โ Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
โ Each resource type Ri has Wi instances.
โ Each process utilizes a resource as follows:
โ request
โ use
โ release
7. 7.7
Deadlock Characterization
โ Mutual exclusion: only one process at a time can use a
resource
โ Hold and wait: a process holding at least one resource
is waiting to acquire additional resources held by other
processes
โ No preemption: a resource can be released only
voluntarily by the process holding it, after that process
has completed its task
โ 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.
Deadlock can arise if four conditions hold simultaneously.
8. 7.8
Resource-Allocation Graph
โ V is partitioned into two types:
โ P = {P1, P2, โฆ, Pn}, the set consisting of all the
processes in the system
โ R = {R1, R2, โฆ, Rm}, the set consisting of all
resource types in the system
โ request edge โ directed edge P1 โ Rj
โ assignment edge โ directed edge Rj โ Pi
A set of vertices V and a set of edges E.
9. 7.9
Resource-Allocation Graph (Cont.)
โ Process
โ Resource Type with 4 instances
โ Pi requests instance of Rj
โ Pi is holding an instance of Rj
P
i
P
i
Rj
Rj
13. 7.13
Basic Facts
โ If graph contains no cycles โ no deadlock
โ If graph contains a cycle โ
โ if only one instance per resource type, then
deadlock
โ if several instances per resource type,
possibility of deadlock
14. 7.14
Methods for Handling Deadlocks
โ Ensure that the system will never enter a
deadlock state
โ Allow the system to enter a deadlock state and
then recover
โ Ignore the problem and pretend that deadlocks
never occur in the system; used by most
operating systems, including UNIX