




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















CompSci 143a
Spring, 2009
6.1 Deadlocks with Reusable and Consumable Resources6.2 Approaches to the Deadlock Problem6.3 A System Model
6.4 Deadlock Detection
6.5 Recovery from Deadlock6.6 Dynamic Deadlock Avoidance
6.7 Deadlock Prevention
CompSci 143a
Spring, 2009
CompSci 143a
Spring, 2009
p1: ...
p2: ...
open(f1,w);
open(f2,w);
open(f2,w);
open(f1,w);
...
...
Deadlock when executed concurrently p1: if (C) send(p2,m);
p2: ...
while(1){...
while(1){...
recv(p2,m);
recv(p1,m);
send(p2,m);
send(p1,m);
... }
... }
Deadlock when
not true
CompSci 143a
Spring, 2009
-^
-^
requests may starve a 200MB request
CompSci 143a
Spring, 2009
Assumptions:– When a process requests a resource, either the request is
fully granted or the process blocks
Resource graph:^ – Vertices are processes, resources, resource units– Edges (directed) represent requests and allocations of
resources
CompSci 143a
Spring, 2009
Resource graph:
Process = CircleResource = Rectangle with small circles for each unitRequest = Edge from process to resource classAllocation = Edge from resource unit to process
Figure 6-
CompSci 143a
Spring, 2009
CompSci 143a
Spring, 2009
11
2 processes
p
1
p
; 2 resources 2
p
1
and
p
2
both need
1
and
2
p
1
requests
1
before
2
and releases
2
before
p
2
requests
2
before
1
and releases
1
before
Figure 6-3: Transitions by
p
only 1
CompSci 143a
Spring, 2009
Graph Reduction:
Repeat the following
p
p
and all request and allocation edges
Deadlock
Graph not completely reducible.
All reduction sequences lead to the same result.
Figure 6-
CompSci 143a
Spring, 2009
-^
Reduce until
p
is removed or graph irreducible
-^
Current state not deadlocked
Next state
deadlocked only if:
a.
Operation was a request by
p
and
b.
p
is deadlocked in
Try to reduce
by
p
CompSci 143a
Spring, 2009
Special Cases of Detection
Knot
: A set K of nodes such that
Deadlock :
(Remove R2->p1: knot R2,p3,R3,p5)(Reverse edge p1->R1): expedient state
CompSci 143a
Spring, 2009
For single-unit resources, cycle
deadlock
p
must have a request edge to
R
R
must have an allocation edge to
p
R
is not available and thus
p
is blocked
Wait-For Graph (wfg):
Show only processes
p
→
R
→
p
2
by
p
→
p
2
:^
p
1
waits for
p
Figure 6-
CompSci 143a
Spring, 2009
Distributed Approach– Detect cycles using probes.– If process
pi
blocked on
p
, it launches probe j
p
→ i
pj
pi
→
pj
→
p
k^
along all request edges, etc.
pi
, cycle is detected Figure 6-
CompSci 143a
Spring, 2009