Unit 3 Part 3
Unit 3 Part 3
DISTRIBUTED
COMPUTING
Deadlock
Req
Speaker
User User
1 2
Req
Mic
What is
deadlock?
1. A deadlock can be defined as a condition where a set of
processes request resources that are held by other processes in
the set.
2. Handling Deadlocks:
a. Deadlock prevention is commonly achieved by either having a process acquire all
the needed resources simultaneously before it begins execution or by pre-
empting a process that holds the needed resource.
b. In the deadlock avoidance approach to distributed systems, a resource is
granted to a process if the resulting global system is safe.
c. Deadlock detection requires an examination of the status of the process–resources
interaction for the presence of a deadlock condition. To resolve the deadlock, we
have to abort a deadlocked process
System
Model
1. A distributed system consists of a set of processors that are connected by a
communication network.
2. The communication delay is finite but unpredictable.
3. A distributed program is composed of a set of n asynchronous processes P1, P2,
, Pi, , Pn that communicate by message passing over the communication
network.
4. Without loss of generality we assume that each process is running on a different
processor.
5. The processors do not share a common global memory and communicate solely
by passing messages over the communication network.
6. There is no physical global clock in the system to which processes have
instantaneous access.
7. The communication medium may deliver messages out of order, messages
may be lost, garbled, or duplicated due to timeout and retransmission,
processors may fail, and communication links may go down.
8. The system can be modeled as a directed graph in which vertices represent the
processes and edges represent unidirectional communication channels
System Model
continued…
● assumptions:
○ The systems have only reusable resources.
○ Processes are allowed to make only exclusive access to
resources.
○ There is only one copy of each resource.
● Running state (also called active state), a process has all the
needed resources and is either executing or is ready for
execution.
● Blocked state, a process is waiting to acquire some
resource.
Wait for Graph
Wait for Graph
● Detection of deadlocks involves
Issues in Deadlock addressing two issues:
maintenance of the WFG and
Detection ●
searching of the WFG for the
Since,
presencein distributed systems,
of cycles (or knots). a
cycle or knot may involve several
sites, the search for cycles greatly
depends upon how the WFG of the
system is represented across the
system. Many algorithms are there
for the same.
Issues in Deadlock - Resolution of
Deadlocks
P1 P2
P3
● Deadlock resolution involves breaking existing wait-for
dependencies between the processes to resolve the
deadlock.
● It involves rolling back one or more deadlocked processes and
assigning their resources to blocked processes so that they can
resume execution.
● Note that several deadlock detection algorithms propagate
information regarding wait-for dependencies along the edges
of the wait-for graph.
● Therefore, when a wait-for dependency is broken, the corresponding
information should be immediately cleaned from the system. If this
Models of
Deadlock
1. Single Resource
Model
2. AND Model
3. OR Model
4. AND-OR Model
5.
6. Unrestricted Model
1. Single Resource
a. a process can have at most one
Model
outstanding request for only one unit
of a resource.
b. Since the maximum out-degree of a
node in a
WFG for the single resource model can be
1, the presence of a cycle in the WFG shall
indicate that there is a deadlock.
2. AND Model
a. a process can request more than one
resource simultaneously and the request
is satisfied only after all the requested
resources are granted to the process.
b.
c. requested
The out resources
degree of a node in may existforat
the WFG
different
AND model can be more than 1.
d. locations.
The presence of a cycle in the WFG
indicates a
deadlock in the AND model. Each node Cycle => Deadlock but not vice
of the WFG in such a model is called an versa
AND node.
OR Model
● a process can make a
request for numerous resources
simultaneously and the request
is satisfied if any one of the
requested resources is granted.
● The requested resources may
exist at different locations. If all
requests in the WFG are OR
requests, then the nodes are
called OR nodes.
● Presence of a cycle in the WFG
of an OR model does not
imply a deadlock in the OR
model.
● In the OR model, the presence of
a knot indicates a deadlock . In a
WFG, a vertex v is in a knot if for
all u :: u is reachable from v : v is
reachable from u.
When deadlock occurs in OR
Model?
● a process Pi is blocked if it has a pending OR request to be satisfied.
● With every blocked process, there is an associated set of
processes called dependent set.
● A process shall move from an idle to an active state on receiving
a grant message
from any of the processes in its dependent set.
● A process is permanently blocked if it never receives a grant message
from any of the processes in its dependent set.
● Intuitively, a set of processes S is deadlocked if all the processes in S are
permanently blocked.
● To formally state that a set of processes is deadlocked, the following
conditions hold true:
○ Each of the process is the set S is blocked.
○ The dependent set for each process in S is a subset of S.
○ No grant message is in transit between any two processes in set S
AND-OR
Model
● a request may specify any combination of and and or in the
resource request.
● For example, in the ANDOR model, a request for multiple resources
can be of the form x and (y or z).
● The requested resources may exist at different locations.
● To detect the presence of deadlocks in such a model, there is
no familiar construct of graph theory using WFG.
● Since a deadlock is a stable property (i.e., once it exists, it does not
go away by itself), this property can be exploited and a deadlock in
the AND-OR model can be detected by repeated application of the
test for OR-model deadlock.
Unrestricted Model
● In this model, only one assumption that the deadlock is stable is
made and hence it is the most general model.
● concerns about properties of the problem (stability and
deadlock) are separated from underlying distributed systems
computations (e.g., message passing versus synchronous
communication).
● Hence, these algorithms can be used to detect other stable
properties as they deal with this general model.
● But, these algorithms are of more theoretical value for distributed
systems since no further assumptions are made about the underlying
distributed systems computations which leads to a great deal of
CS 3551
DISTRIBUTED
COMPUTING
Chandy–Misra–Haas algorithm for the AND model
Algorithm
Key Points
Performanc
e
● In the algorithm, one probe message (per deadlock detection
initiation) is sent on every edge of the WFG which connects
processes on two sites.
● Thus, the algorithm exchanges at most m(n − 1)/2 messages
to detect a deadlock that involves m processes and spans over
n sites.
● The size of messages is fixed and is very small (only three
integer words). The delay in detecting a deadlock is O(n).
CS 3551
DISTRIBUTED
COMPUTING
Chandy–Misra–Haas algorithm for the OR model
● Uses diffusion computation ● Deadlock is detected if a
● Msg can be query(i,j,k) or process gets reply to all
reply(i,j,k) query sent out
Any blocked process initiates deadlock detection
Algorithm
Key Points
Performance