Deadlock
Deadlock
Deadlock
Deadlock
A system consists of finite number of
resources.
Multiple concurrent processes have to
compete to use a resource.
The sequence of events to use a resource:
1. Request
2. Allocate
3. Release
Cont…
Request
Number of units requested may not exceed the
total no. of available units of the resource.
Allocate
Allocate the resource as soon as possible.
Maintain a table of resources allocated or
available.
Cont…
Release
Release the resources after the process has
finished using the allocated resource.
Allocation strategy:
Allocate the resource to the requester if free.
Non-Preemptable resource:
One that cannot be taken away from a process to which
it was allocated until the process voluntarily releases it.
Resource Types
Two general categories of resources:
Reusable &
Consumable.
Hold-and-wait condition
Processes are allowed to request for new resources
without releasing the resources that are currently held.
Cont…
No-preemption condition
A resource that has been allocated to a process
becomes available for allocation to another process
only after it has been voluntarily released by the
process holding it.
Circular-wait condition
Two or more processes must form a circular chain in
which each process is waiting for a resource that is
held by the next process of the chain.
Directed graph:
A pair (N,E), where N is a nonempty set of
nodes and E is a set of directed edges.
Path :
A sequence of nodes (a,b,c,….i,j) of a directed
graph such that (a,b), (b,c),….. (i,j) are
directed edges.
Cont…
Cycle :
A path whose first and last nodes are the
same.
Reachable set:
The reachable set of a node ‘a’ is the set of all
nodes ‘b’ such that a path exists from ‘a’ to ‘b’.
Knot: A nonempty set ‘K’ of nodes such
that the reachable set of each node in ‘K’
is exactly the set ‘K’.
It always contains one or more cycles.
A directed graph
Cycles :
a c 1. (a,b,c,d,e,f,a)
2. (b,c,d,e,b)
Knot:
d {a,b,c,d,e,f}
f
e
Resource allocation graph
Both the set of nodes and the set of edges are
partitioned into two types, resulting in the
following graph elements.
1. Process nodes
2. Resource nodes
3. Assignment edges
4. Request edges
Cont…
Pi A process named Pi
P1
R2 R1 R3
P2
Cont…
2. A cycle in the graph is a necessary but
not a sufficient condition for deadlock
if one or more of the resource types requested
by the processes forming the cycle have more
than one unit.
P1
R2 P2 R1 R3
P3
Wait-for graph
A simplified graph, obtained from the original
resource allocation graph by removing the
resource nodes and collapsing the appropriate
edges.
R2 R1
P3 P2 P3 P2
Unsafe state:
A system state if no safe sequence exists.
Cont…
Some assumptions of the algorithm:
The advance knowledge of the resource
requirements of the various processes is
available.
Problem :
Reordering may become inevitable when new
resources are added to the system.
Preemption
A preemptable resource is one whose
state can be easily saved and restored
later.
Progress property
Deadlock must be detected in a finite amount of
time.
Safety property
If a deadlock is detected, it must indeed exist.
No phantom deadlocks.
Cont…
Steps to construct WFG for a distributed
system:
Construct the resource allocation graph for
each site of the system.
R1 R2
P1 P3
P2 P2
Site S1 Site S1
P2
P1 R3 P3 P1 P3
Site S2 Site S2
(c) Global WFG by
(A) Resource (B) WFGs taking the union of
allocation graph for corresponding to the two local WFGs of
each site graphs in (a) (b).s
Cont…
Local WFGs are not sufficient to
characterize all deadlocks in a distributed
system.
Techniques are:
Centralized
Hierarchical
Distributed
Centralized approach for deadlock detection
Use of local coordinator for each site
Maintains a WFG for its local resources
Continuous transfer
Transfer of message whenever a new edge is added
to or deleted from the local WFG.
Periodic transfer
Transfer-on-request
Cont…
Drawbacks of centralized deadlock
detection approach:
Vulnerable to failures of the central
coordinator.
P1 P3 P1 P3
R3
R3 P3
R1 R2 R1 R2
P2 P2
Resource allocation Resource allocation
Resource allocation
graph of the local graph maintained
graph of the local
coordinator of site by the central
coordinator of site
S2 coordinator
S1
P3 P1 P3
R3
P1 R3 P3
R1 R2 R1 R2
P2 P2
P1 R3 P3
R1 R2
P2
Central coordinator
P7 P6 Controller G
P1 P3 P4 P5
P5 P6 P7
P2 P7
Controller E Controller F
P1 P3 P1 R3 P3
P5 R6 P6 P6 R7 P7
R1 R2 P4 R4 P5
P2 R5 P7 Site S3 Site S4
Controller C Controller D
Site S1 Site S2
Controller A Controller B
Cont…
Deadlock cycle
(p1,p3,p2,p1) of site S1 and S2 gets reflected
in the WFG of controller E.
Algorithms are:
WFG-based distributed algorithm for deadlock
detection.
P1 P3
Pex
P4 P2
P1 P3 P5
Site S1 P4 P2
Site S1
P2
Pex
P1 P5 Updating local
P3
P1 P3 P5 WFGs of site S2
after receiving the
Site S2 Site S2 deadlock detection
message from site
Local WFGs Local WFGs after S1.
addition of node
Pex
Cont…
If a local WFG contains a cycle that:
does not involve node Pex, a deadlock that involves only
local processes of that site has occurred – Resolved
Locally
Solution:
Assign a unique identifier to each process.
Probe-based distributed algorithm for
deadlock detection
Proposed by Chandy et al. in 1983.
(P1,P1,P3) (P1,P3,P5)
P1 P3 P5
(P1,P2,P1)
(P1,P3,P2)
(P1,P2,P4)
P4 P2
Site S1 Site S2
Cont…
Features of the CMH algorithm:
Easy to implement.
Each message is of fixed length.
Few computational steps.
Low overhead of the algorithm
No graph construction and information
collection
Doesn’t detect false deadlocks
Does not require any particular structure
among the processes.
Methods for recovery from deadlock
Asking for operator intervention.
Termination of process (es).
Rollback of process (es).
Asking for operator intervention
Inform the operator about the deadlock.
Requirements:
Analyze the resource requirements and
interdependencies of the processes involved in
a deadlock cycle.
Rollback of process
Reclaim the needed resources from the
processes that were selected for being
killed.
Rollback the process to a point where the
resource was not allocated to the process.
Processes are checkpointed periodically.
Approach is less expensive than the
process termination approach.
Extra overhead involved in periodic
checkpointing of all the processes.
Issues in recovery from deadlock
Selection of victim (s)
Use of transaction mechanism