0% found this document useful (0 votes)
22 views13 pages

Unit - 3 - DC - Distributed - Deadlock (Part-2)

Uploaded by

Muhammad Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views13 pages

Unit - 3 - DC - Distributed - Deadlock (Part-2)

Uploaded by

Muhammad Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)

UNIT III MUTEX AND DEADLOCK 10

Distributed Mutual exclusion Algorithms: Introduction – Preliminaries – Lamport’s algorithm –


RicartAgrawala’s Algorithm –– Token-Based Algorithms – Suzuki-Kasami’s Broadcast Algorithm;
Deadlock Detection in Distributed Systems: Introduction – System Model – Preliminaries –
Models of Deadlocks – Chandy-Misra-Haas Algorithm for the AND model and OR Model.

Introduction:

● Deadlock Problem: In distributed systems, processes may request resources in any


sequence, and while holding some resources, they may request others. This situation can
lead to a deadlock, where each process in a set is waiting for a resource held by another
process in the same set.
● Deadlock Strategies:
1. Deadlock Prevention: This approach ensures deadlocks cannot occur by
imposing constraints on how resources are requested. Common methods include:
■ Requiring processes to acquire all needed resources at once.
■ Preempting a process holding resources if another process needs them.
2. Deadlock Avoidance: This strategy checks if granting a resource will keep the
system in a "safe state," where no deadlock can happen. Resources are allocated
only if it is safe.
3. Deadlock Detection: This approach periodically examines the system to identify
whether a deadlock has occurred. If detected, one of the deadlocked processes is
aborted to resolve the situation.

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.

Wait-for Graph (WFG):

● 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.

Deadlock Handling Strategies:

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:

Prevention = Avoids the issue upfront by being strict, but inefficient.

Avoidance = Tries to predict and prevent issues, but complex to implement.

Detection = Lets the issue happen, then identifies and fixes it, making it the most flexible and
realistic approach for distributed systems.

Issues in deadlock detection

Deadlock Detection Issues:

Deadlock detection in distributed systems involves two major tasks:

1. Detection: Identifying existing deadlocks.


2. Resolution: Breaking the deadlock by releasing resources and rolling back
processes.

Deadlock Detection:

The main tasks involved in detecting deadlocks are:

● Maintenance of the Wait-For Graph (WFG): A distributed system's state is represented


by the WFG, where nodes represent processes, and edges represent dependencies.
Cycles in this graph indicate deadlocks.
● Searching for Cycles: Since cycles or knots may span across multiple sites in a
distributed system, searching for them is complex. Depending on how the WFG is
maintained and how cycle detection is performed, deadlock detection algorithms can be:
○ Centralized: One site is responsible for maintaining and checking the WFG.
○ Distributed: Each site maintains its part of the WFG and collaborates to detect
cycles.

4
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)

○ Hierarchical: A combination of centralized and distributed methods.

Correctness Criteria:

A deadlock detection algorithm must meet two 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.

Challenges in Deadlock Detection:

● 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:

Once a deadlock is detected, resolution requires breaking wait-for dependencies between


processes. This can involve:

● 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.

Key Challenges in Resolution:

● 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.

2. AND Model (Multiple Resource Requests):

● 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

3. OR Model (Any Resource from a Set):

● 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 Algorithm for the AND model:

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

1.Wait-For Graph (WFG):

○ Represents the dependencies between processes.


○ If a process Pi is waiting for a resource held by process Pj, there’s an edge from
Pi to Pj in the graph.
○ A deadlock occurs when there’s a cycle in this graph.

2. Probe Message:

7
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)

● A probe is a triplet (i,j,k) where:


○ i is the process that initiated the deadlock detection.
○ j is the current sender of the probe (it originates from the home site of process Pj
).
○ k is the current receiver (i.e., the home site of process Pk).
● The probe travels along the edges of the WFG.
● A deadlock is detected if the probe message comes back to the initiator process Pi.

3.Process Dependencies:

● Process Pj is dependent on Pk if there exists a chain of blocked processes


Pj,Pi1,Pi2,…,Pk, such that each process (except Pk) is waiting for a resource held by the
next process in the chain.
● Pj is locally dependent on Pk if both processes are on the same site.

Algorithm:

8
CS3551 DISTRIBUTED COMPUTING UNIT III MUTEX AND DEADLOCK(Part-2)

Summary of Performance Characteristics

● Message Complexity: At most m(n−1)/2 messages are exchanged for detecting a


deadlock involving m processes over n sites.
● Message Size: The size of the messages is small and fixed (three integers).
● Detection Delay: The delay in detecting a deadlock is O(n), where n is the number of
sites involved.

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.

This situation creates a circular wait, indicating a deadlock.

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)

■P3 checks if it is blocked (which it is, waiting for P1).


■It updates its dependency array: dependent 3[1]=true P3 sends a new
probe back: PROBE(1, 3, 1) to Process P1.
■ Meaning: Process P3 is forwarding the probe back to check the
status of Process P1.
4. Probe Returns to P1:
○ When P1 receives PROBE(1, 3, 1):
■ It recognizes that the probe has returned to it, indicating a cycle in the
wait-for graph.
■ Therefore, P1 declares a deadlock because the probe has looped back to
itself, confirming that the processes are in a circular wait.

Visual Representation of the Dependency Cycle


markdown
Copy code
P1 --> P2 --> P3
^ |
|_______________|

Summary

In this simple example:

● 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.

Chandy–Misra–Haas algorithm for the OR model

The Chandy-Misra-Haas algorithm for the OR model is a distributed deadlock detection


algorithm that uses diffusion computation.

A blocked process determines if it is deadlocked by initiating a diffusion computation. Two types


of messages are used in a diffusion computation: query(i, j, k) and reply(i, j, k), denoting that

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.

In the Chandy–Misra–Haas algorithm for the OR model, diffusion computation can be


understood in the context of the algorithm’s decentralized way of detecting deadlocks. Diffusion
here refers to the propagation of "probe" messages among processes in a distributed system,
where each process participates in local interactions by sending and receiving probes, and the
overall system detects deadlocks through these local interactions.

Engaging query-first time receiving query forward query() to DS

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:

● P1 is waiting for a resource held by P2.


● P2 is waiting for a resource held by P3.
● P3 is waiting for a resource held by P1.

This creates a cyclic dependency, which can potentially result in a deadlock.

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

You might also like