Vous êtes sur la page 1sur 3

Handling deadlocks What is a deadlock?

n definition, wait-for graphs n deadlock – a set of processes is blocked waiting for


n fundamental causes of deadlocks requirements that cannot be satisfied
n resource allocation graphs and conditions for deadlock n illustrated by a wait-for-graph (WFG)
existence u nodes – processes in the system
n approaches to handling deadlocks u directed edges – wait-for blocking relation
u deadlock prevention u a cycle in WFG indicates a deadlock
u deadlock avoidance n starvation – a process is indefinitely prevented from making
u deadlock detection/resolution progress
F centralized algorithms u deadlock implies starvation, is the converse true?

F distributed algorithms

F hierarchical algorithms

1 2

Fundamental causes of deadlocks Resource allocation graph


n The deadlock conditions can be modeled using a directed graph called
n Mutual exclusion — if one process holds a resource, other
a resource-allocation graph (RAG)
processes requesting that resource must wait until the process
releases it (only one can use it at a time) u 2 kinds of nodes:
F Boxes — represent resources
n Hold and wait — processes are allowed to hold one (or more)
resource and be waiting to acquire additional resources that are • Instances of the resource are represented as dots within
being held by other processes the box
n No preemption — resources are released voluntarily; neither F Circles — represent processes

another process nor the OS can force a process to release a u 2 kinds of (directed) edges:
resource F Request edge — from thread to resource — indicates the
n Circular wait — there must exist a set of waiting processes thread has requested the resource, and is waiting to acquire it
such that P0 is waiting for a resource held by P1, P1 is waiting F Assignment edge — from resource instance to thread —
for a resource held by P2, … Pn-1 is waiting for a resource held indicates the thread is holding the resource instance
by Pn, and Pn is waiting for a resource held P0
u When a request is made, a request edge is added
F When request is fulfilled, the request edge is transformed into
an assignment edge
F When process releases the resource, the assignment edge is
3 deleted 4

RAG with single resource instances RAG with multiple resource instances

r1 r2 r1 r2 r2
r1 r2 r1

p1 p2 p3 p1 p2 p3 p2 p3
p1 p2 p3 p1

r3 r4 r3 r4 r4
r3 r4 r3

n a cycle in RAG with single resource instances is necessary and n cycle does not indicate deadlock
sufficient for deadlock n knot – strongly connected subgraph (no sinks) with no outgoing edges
n a knot in RAG is necessary and sufficient for deadlock

5 6
Deadlock prevention and avoidance Deadlock detection
n Deadlock prevention — eliminate one of the 4 deadlock conditions n Deadlock detection and resolution — detect, then break the deadlock
u examples n detection
F acquire all resources before proceeding (no wait while hold) u issues
F allow preemption (eliminate 3d condition) F maintenance of WFG

F prioritize processes and assign resources in the order of F search of WFG for deadlocks
priorities (no circular wait) u requirements
u may be inefficient F progress – no undetected deadlocks
n Deadlock avoidance — consider each resource request, and only fulfill F safety – no false (phantom) deadlocks
those that will not lead to deadlock n resolution
u Stay in a safe state — a state with no deadlock where resource
u roll back one or more processes to break dependencies in WFG
requests can be granted in some order such that all processes will and resolve deadlocks
complete
u may be inefficient
F Must know resource requirements of all processes in advance

F Resource request set is known and fixed, resources are known


and fixed
7 8
F Complex analysis for every request

Distributed deadlock detection Simple centralized deadlock detection


algorithms n A central coordinator maintains a global wait-for graph (WFG) for
the system
n Centralized algorithm - coordinator maintains global WFG and
n All sites request and release resources (even local resources) by
searches it for cycles
sending request and release messages to the coordinator
u simple algorithm
n When coordinator receives a request/release, it
u Ho and Ramamoorthy’s one- and two-phase algorithms
u updates the global WFG
n Distributed algorithms - Global WFG, with responsibility for u checks for deadlocks
detection spread over many sites
n problems
u Obermarck’s path-pushing
u large communication overhead, coordinator is a performance
u Chandy, Misra, and Haas’s edge-chasing bottleneck and single point of failure, etc.
u diffusion u may report phantom deadlock
n Hierarchical algorithms - hierarchical organization, site detects
deadlocks involving only its descendants
u Menasce and Muntz’s algorithm
u Ho and Ramamoorthy’s algorithm

9 10

Problem of False Deadlock Ho and Ramamoorthy two phase


centralized deadlock detection
p1 p1 p1
n Every site maintains a status table, containing status of all local
processes
p2 p2 p3 p3 u Resources held, resources waiting on
n Periodically, coordinator requests all status tables, builds a WFG, and
site A coordinator site B searches it for cycles
u No cycles - no deadlock
n Now assume process p1 releases resource p3 is waiting on
u If cycle is found, coordinator again requests all status tables, again
n Slightly thereafter, p2 requests resource p3 is holding builds a WFG, but this time uses only those edges common to both
n However, first message reaches coordinator after second message sets of status tables
n The global WFG now has a false cycle, which leads to a report of false n Rationale was that by using information from two consecutive reports,
deadlock coordinator would get a consistent view of the state
u However, it was later shown that a deadlock in this WFG does not
imply a deadlock exists (see 1 phase alg.)
u So, the HR-two-phase algorithm may reduce the possibility of
reporting false deadlocks, but doesn’t eliminate it
11 13
Ho and Ramamoorthy one-phase
centralized deadlock detection
n Every site maintains two tables
u all local processes and resources the locked
u resources locked at this site (by both local and non-local
processes)
n one site periodically requests both tables (once) constructs WFG;
WFG only includes the info on non local processes if this info is
matched by the process site and resource site
u if cycle – deadlock
u if not – no deadlock
n correctly detects deadlocks by eliminating inconsistency of reporting
due to message propagation delay
n more space overhead than 2-phase H&R

14

Vous aimerez peut-être aussi