Unit - 3 - DC - Distributed - Deadlock (Part-2)
Unit - 3 - DC - Distributed - Deadlock (Part-2)
Introduction:
1
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
System model:
Assumptions:
● Reusable resources: The system uses resources that can be reused after release.
● Exclusive access: Each process can exclusively access a resource.
● Single copy of resources: Only one instance of each resource exists.
● The system state can be represented as a Wait-for Graph (WFG). In this graph:
○ Nodes represent processes.
○ Edges represent resource dependencies between processes. Specifically, an
edge from process P1 to process P2 indicates that P1 is blocked and waiting for
P2 to release a resource.
● Deadlock Detection:
○ A deadlock occurs if there is a cycle or knot in the WFG. A cycle indicates that
a group of processes is waiting on each other in a circular dependency, which
leads to deadlock.
2
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
Example of WFG:
In the given example (Figure 10.1), several processes are illustrated in a potential deadlock
situation:
● Process P11 at site 1 is waiting for resources held by process P21 at the same site
and process P32 at site 2.
● Process P32 is in turn waiting for a resource held by process P33 at site 3.
● Process P21 is waiting for process P24 at site 4.
● If process P33 also starts waiting on process P24, this could lead to a cycle in the
WFG, causing a deadlock.
The WFG model allows the detection of deadlocks by identifying such cycles in the resource
allocation dependencies across the distributed system.
1. Deadlock Prevention:
○ Involves either having a process acquire all necessary resources before starting
execution or preempting a process that holds a needed resource.
○ Impractical in Distributed Systems: Due to the lack of accurate global state
knowledge and the delays in inter-site communication, this approach is
inefficient and unsuitable for distributed systems.
2. Deadlock Avoidance:
○ Resources are allocated to processes only if the resulting global system state
remains safe (i.e., no possibility of deadlock).
○ Challenges in Distributed Systems: Global state tracking is complex due to
the distributed nature of the system, making deadlock avoidance impractical.
3. Deadlock Detection:
3
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
○ This approach involves examining the system for cyclic wait conditions between
processes and resources. Deadlocks are detected by checking for cycles in the
system's resource allocation graph.
○ Best Option for Distributed Systems: Unlike prevention and avoidance,
detection is considered the most feasible approach for handling deadlocks in
distributed systems because it doesn't require continuous global state tracking or
preemptive resource allocation.
The chapter focuses on deadlock detection techniques, which are more practical in
distributed systems due to their ability to identify deadlocks after they occur, rather than trying to
prevent them preemptively.
Summary:
Detection = Lets the issue happen, then identifies and fixes it, making it the most flexible and
realistic approach for distributed systems.
Deadlock Detection:
4
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
Correctness Criteria:
1. Progress (no undetected deadlocks): The algorithm must detect all deadlocks within a
finite time. Once a deadlock forms, the algorithm should continue progressing until it
detects the deadlock, without waiting for other events.
2. Safety (no false deadlocks): The algorithm should avoid reporting false or "phantom"
deadlocks. In distributed systems, due to inconsistent or outdated WFG information at
different sites, false deadlocks can be detected when segments of a cycle exist at
different times across the system.
● Inconsistent Information: The lack of a global memory and clock can lead to situations
where different parts of the system detect a cycle that never existed in real-time but
seemed to exist due to timing differences. This can lead to false deadlocks.
Deadlock Resolution:
● Rolling Back Processes: Releasing the resources held by one or more deadlocked
processes and allowing blocked processes to continue.
● Cleaning the WFG: After breaking dependencies, it is crucial to promptly update and
clean the WFG. Failure to remove broken dependencies can result in the detection of
phantom deadlocks.
● Timely WFG Updates: Ensuring that broken dependencies are quickly removed to
avoid phantom deadlocks.
● Propagating Updates: If wait-for dependencies are not cleaned correctly, lingering
information can lead to errors in subsequent deadlock detection efforts.
5
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
Models of Deadlocks:
In distributed systems, several models describe how processes request and acquire resources,
each with varying complexity and implications for deadlock detection. The primary models
include:
1. Single-Resource Model:
● Description: Each process can request only one resource at a time and can have at most
one outstanding request.
● Deadlock Detection: Simple to detect because the Wait-for Graph (WFG) will have
cycles indicating deadlock. Since each process waits for only one resource, the maximum
out-degree of any node in the WFG is 1, and a cycle in the graph signifies deadlock.
● Example: A process needs a printer and waits until it becomes available.
● Description: A process may request multiple resources simultaneously and can only
proceed when all requested resources are available.
● Deadlock Detection: Deadlock occurs when a group of processes forms a cycle where
each process holds resources needed by the next. Detecting deadlock in this model is
more complex because processes can wait on multiple resources at once.
● Example: A process might request both a printer and a scanner and will wait until both
are available simultaneously
Consider the example WFG described in Figure 10.1. Process P11 has two outstanding resource
requests. In case of the AND model, P11 shall become active from idle state only after both the
resources are granted. There is a cycle P11 → P21 →P24 →P54 →P11, which corresponds to a
deadlock situation.
6
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
In the AND model, if a cycle is detected in the WFG, it implies a deadlock but not vice versa. That
is, a process may not be a part of a cycle, it can still be deadlocked. Consider process P44 in
Figure 10.1. It is not a part of any cycle but is still deadlocked as it is dependent on P24, which is
deadlocked. Since in the single-resource model, a process can have at most one outstanding
request, the AND model is more general than the single-resource model
● Description: A process requests multiple resources but can proceed if it gets any one of
the resources from the set.
● Deadlock Detection: Detection is more challenging because even if one resource
becomes available, the process may proceed, potentially breaking a deadlock cycle.
However, cycles in the WFG still suggest possible deadlock conditions.
● Example: A process requests either a printer or a scanner, whichever becomes available
first.
Chandy–Misra–Haas’s distributed deadlock detection algorithm for the AND model is designed
for distributed systems where processes may need multiple resources to proceed, and those
resources are spread across different sites. In this model, the algorithm detects deadlocks
through edge-chasing using a special message called a probe.
The technique is called edge-chasing because the special message (probe) chases along the
edges of the WFG, following the "wait-for" relationships between processes, searching for cycles.
Key Concepts
2. Probe Message:
7
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
3.Process Dependencies:
Algorithm:
8
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
Example:
Let’s illustrate the Chandy–Misra–Haas deadlock detection algorithm using a simple example with
three processes P1, P2, and P3 in a distributed system. We’ll represent how the algorithm detects
deadlocks based on local dependencies and probe messages.
● Process States:
○ Process P1 is waiting for a resource held by Process P2.
○ Process P2 is waiting for a resource held by Process P3.
○ Process P3 is waiting for a resource held by Process P1.
Initial Setup
1. Resources:
○ P1 holds Resource R1 and is waiting for Resource R2 held by P2.
○ P2 holds Resource R2 and is waiting for Resource R3 held by P3.
○ P3 holds Resource R3 and is waiting for Resource R1 held by P1.
Step-by-Step Execution
1. Initiation by P1:
○ P1 is blocked and initiates the probe process because it is waiting for P2.
○ It sends a probe message: PROBE(1, 1, 2).
■ Meaning: Process P1 initiated this probe, and it is being sent to Process
P2.
2. Probe Received by P2:
○ When P2 receives PROBE(1, 1, 2):
■ P2 checks if it is blocked (which it is, waiting for P3).
■ It updates its dependency array: dependent 2[1]=true
■ P2 sends a new probe: PROBE(1, 2, 3) to Process P3.
■ Meaning: Process P2 is sending this probe to check the status of
Process P3 on behalf of Process P1.
3. Probe Received by P3:
○ When P3 receives PROBE(1, 2, 3):
9
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
Summary
● The deadlock detection process was initiated by P1, which was blocked and waiting for
P2.
● Each process updated its dependency status upon receiving a probe.
● A cycle was detected when P3 sent a probe back to P1, leading to the conclusion of a
deadlock.
This step-by-step execution illustrates how the Chandy–Misra–Haas algorithm effectively traces
dependencies and detects deadlocks in a distributed system using probe messages.
10
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
they belong to a diffusion computation initiated by a process Pi and are being sent from process
Pj to process Pk.
Performance analysis For every deadlock detection, the algorithm exchanges e query
messages and e reply messages, where e = n(n−1) is the number of edges.
11
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
Algorithm:
Example
Let's consider three processes: P1, P2, and P3. Assume the following dependencies:
1. P1 Gets Blocked:
○ P1 sends a query(1, 1, 2) to P2, as P2 is in its dependent set (P1 is waiting
on P2).
○ P1 sets num1 = 1 (it expects one reply) and wait1 = true.
2. P2 Receives the Query:
○ Since P2 is also waiting (on P3), it forwards the query by sending query(1, 2,
3) to P3.
○ P2 sets num2 = 1 (it expects one reply from P3) and wait2 = true.
3. P3 Receives the Query:
○ P3 is waiting on P1, so it sends a query(1, 3, 1) back to P1.
○ P3 sets num3 = 1 and wait3 = true.
4. P1 Receives the Query Again:
○ Since P1 is already waiting (wait1 = true), it sends a reply(1, 1, 3) to
P3.
5. P3 Receives the Reply:
12
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)
○ P3 decrements its counter num3 to 0, indicating that it has received all replies.
○ It sends a reply(1, 3, 2) to P2.
6. P2 Receives the Reply:
○ P2 decrements its counter num2 to 0 and sends a reply(1, 2, 1) to P1.
7. P1 Receives the Reply:
○ P1 decrements its counter num1 to 0. Since P1 initiated the query (i.e., i = k), it
declares a deadlock.
13