0% found this document useful (0 votes)
53 views28 pages

Unit 3DC

for engineering students -distributed computing 3rd year

Uploaded by

lokesh.wrnx
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)
53 views28 pages

Unit 3DC

for engineering students -distributed computing 3rd year

Uploaded by

lokesh.wrnx
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/ 28

CS3551-DISTRIBUTED COMPUTING –UNIT 3

UNIT III DISTRIBUTED MUTEX AND DEADLOCK


Distributed Mutual exclusion Algorithms: Introduction – Preliminaries – Lamport’s
algorithm – Ricart- Agrawala’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.
3.1. DISTRIBUTED MUTUAL EXCLUSION ALGORITHMS: INTRODUCTION
 Mutual exclusion is a fundamental problem in distributed computing systems.
 Mutual exclusion ensures that concurrent access of processes to a shared resource or
data is serialized, that is, executed in mutually exclusive manner.

Figure 1: Three processes accessing a shared resource (critical section)


simultaneously.
 Mutual exclusion in a distributed system states that only one process is allowed to
execute the critical section (CS) at any given time.
 Message passing is the sole means for implementing distributed mutual exclusion.
There are three basic approaches for implementing distributed mutual exclusion:
1. Token based approach
2. Non-token based approach
3. Quorum based approach
1. In the token-based approach,
 A unique token (also known as the PRIVILEGE message) is shared among the sites.
 A site is allowed to enter its CS if it possesses the token and it continues to hold the
token until the execution of the CS is over.
 Mutual exclusion is ensured because the token is unique.
 Example:Suzuki-Kasami’s Broadcast Algorithm.
2. In the non-token based approach,
 Two or more successive rounds of messages are exchanged among the sites to
determine which site will enter the CS next.
 This approach use timestamps instead of sequence number to order requests for the
critical section.
 When ever a site make request for critical section, it gets a timestamp. Timestamp is
also used to resolve any conflict between critical section requests.
 All algorithm which follows non-token based approach maintains a logical clock.

1
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Logical clocks get updated according to Lamport’s scheme.


 Example: Lamport's algorithm, Ricart–Agrawala algorithm
3. In the quorum-based approach,
 Instead of requesting permission to execute the critical section from all other sites,
Each site requests only a subset of sites which is called a quorum.
 Any two subsets of sites or Quorum contains a common site.
 This common site is responsible to ensure mutual exclusion.
 Example: Maekawa’s Algorithm

OBJECTIVES OF MUTUAL EXCLUSION ALGORITHMS


 Guarantee mutual exclusion (required)
 Freedom from deadlocks (desirable)
Freedom from starvation -- every requesting site should get to enter CS in a
finitetime (desirable)
Fairness -- requests should be executed in the order of arrivals, which would be
based on logical clocks (desirable)
Fault tolerance -- failure in the distributed system will be recognized and therefore
not cause any unduly prolonged disruptions (desirable)

3.2. PRELIMINARIES
We describe here,
1. System model,
2. Requirements that mutual exclusion algorithms
3. Metrics we use to measure the performance of mutual exclusion algorithms.
1. SYSTEM MODEL
 The system consists of N sites, S1, S2, ..., SN. We assume that a single process is
running on each site.
 The process at site Si is denoted by pi.
 A process wishing to enter the CS, requests all other or a subset of processes by
sending REQUEST messages, and waits for appropriate replies before entering the CS.
While waiting the process is not allowed to make further requests to enter the CS.
 A site can be in one of the following three states:
1. Requesting the Critical Section.
2. Executing the Critical Section.
3. Neither requesting nor executing the CS (i.e., idle).
 In the ‘requesting the CS’ state, the site is blocked and can not make further requests
for the CS. In the ‘idle’ state, the site is executing outside the CS.
 In the token-based algorithms, a site can also be in a state where a site holding the
token is executing outside the CS. Such state is referred to as the idle token state.
 At any instant, a site may have several pending requests for CS. A site queues up these

2
CS3551-DISTRIBUTED COMPUTING –UNIT 3

requests and serves them one at a time.


 We assume that channels reliably deliver all messages, sites do not crash, and the
network does not get partitioned.
 Some mutual exclusion algorithms are designed to handle such situations. Many
algorithms use Lamport-style logical clocks to assign a timestamp to critical section
requests.
 Timestamps are used to decide the priority of requests in case the of a conflict.
 A general rule followed is that the smaller the timestamp of a request, the higher its
priority to execute the CS.
 We use the following notations:
o N denotes the number of processes or sites involved in invoking the critical
section,
o T denotes the average Message Time Delay and E denotes the average critical
section Execution Time.

2. REQUIREMENTS OF MUTUAL EXCLUSION ALGORITHMS


A mutual exclusion algorithm should satisfy the following properties:
a. Safety Property: The safety property states that at any instant, only one process can
execute the critical section. This is an essential property of a mutual exclusion algorithm.
b. Liveness Property: This property states the absence of deadlock and starvation. Two or
more sites should not endlessly wait for messages which will never arrive. In addition, a site
must not wait indefinitely to execute the CS while other sites are repeatedly executing the CS.
That is, every requesting site should get an opportunity to execute the CS in finite time.
c. Fairness: Fairness in the context of mutual exclusion means that each process gets a fair
chance to execute the CS.
Note: The first property is absolutely necessary and the other two properties are considered
important in mutual exclusion algorithms
3. PERFORMANCE METRICS
The performance of mutual exclusion algorithms is generally measured by the following four
metrics:
a. Message complexity: It is the number of messages that are required per CS execution by a
site.
b. Synchronization delay: After a site leaves the CS, it is the time required and before the next
site enters the CS (sees Figure 9.1).

3
CS3551-DISTRIBUTED COMPUTING –UNIT 3

c. Response time: It is the time interval a request waits for its CS execution to be over after
its request messages have been sent out (see Figure 9.2).

Figure 9.2: Response Time


d. System throughput: It is the rate at which the system executes requests for the CS. If SD is
the synchronization delay and E is the average critical section execution time, then the
throughput is given by the following equation:
System Throughput=1/(SD+E)
Generally, the value of a performance metric fluctuates statistically from request to request
and we generally consider the average value of such a metric.
Low and High Load Performance:
The load is determined by the arrival rate of CS execution requests. Two special loading
conditions, viz., “low load" and “high load".
 Under low load conditions, there is seldom more than one request for the critical
section present in the system simultaneously.
 Under heavy load conditions, there is always a pending request for critical section at a
site.
Best and worst case performance
 In the best case, prevailing conditions are such that a performance metric attains the
best possible value. For example, the best value of the response time is a roundtrip
message delay plus the CS execution time, 2T +E.
 For examples, the best and worst values of the response time are achieved when
load is, respectively, low and high;
 The best and the worse message traffic is generated at low and heavy load conditions,
respectively.
.
3.3. LAMPORT’S ALGORITHM
 Lamport’s Distributed Mutual Exclusion Algorithm is a permission based algorithm
proposed by Lamport as an illustration of his synchronization scheme for
distributed systems.
 In permission based timestamp is used to order critical section requests and to

4
CS3551-DISTRIBUTED COMPUTING –UNIT 3

resolve any conflict between requests.


 In Lamport’s Algorithm critical section requests are executed in the increasing
order of timestamps i.e a request with smaller timestamp will be given permission
toexecute critical section first than a request with larger timestamp.
 Three type of messages ( REQUEST, REPLY and RELEASE) are used and
communication channels are assumed to follow FIFO order.
 A site send a REQUEST message to all other site to get their permission to
entercritical section.
 A site send a REPLY message to requesting site to give its permission to enter
thecritical section.
 A site send a RELEASE message to all other site upon exiting the critical section.
 Every site Si, keeps a queue to store critical section requests ordered by their
timestamps.
 request_queuei denotes the queue of site Si.
 A timestamp is given to each critical section request using Lamport’s logical clock.
 Timestamp is used to determine priority of critical section requests. Smaller
timestamp gets high priority over larger timestamp. The execution of critical section
request is always in the order of their timestamp.
The Algorithm
1. Requesting the critical section:
• When a site Si wants to enter the CS, it broadcasts a REQUEST(tsi, i) message to all
other sites and places the request on request_queuei. ((tsi, i) denotes the timestamp of
the request.)

• When a site Sj receives the REQUEST(tsi, i) message from site Si, places site Si’s Request
on request_queuej and it returns a time stamped REPLY message to Si.
2. Executing the critical section:

Site Si enters the CS when the following two conditions hold:

L1: Si has received a message with timestamp larger than (tsi, i) from all other sites.

L2: Si’s request is at the top of request_queuei.

3. Releasing the critical section:

 Site Si, upon exiting the CS, removes its request from the top of its request queue and
broadcasts a time stamped RELEASE message to all other sites.

 When a site Sj receives a RELEASE message from site Si, it removes Si’s request
from its request queue. When a site removes a request from its request queue, its own

5
CS3551-DISTRIBUTED COMPUTING –UNIT 3

request may come at the top of the queue, enabling it to enter the CS. Clearly, when a
site receives a REQUEST, REPLY or RELEASE message, it updates its clock using
the timestamp in the message.
Correctness
Theorem 1: Lamport’s algorithm achieves mutual exclusion.
Proof: Proof is by contradiction.
 Suppose two sites Si and Sj are executing the CS concurrently. For this to happen
conditions L1 and L2 must hold at both the sites concurrently.
 This implies that at some instant in time, say t, both Si and Sj have their own requests
at the top of their request_queues and condition L1 hold at them. Without loss of
generality, assume that Si’s request has smaller timestamp than the request of Sj.
 From condition L1 and FIFO property of the communication channels, it is clear that at
instant t the request of Si must be present in request_queuej when Sj was executing its
CS.
 This implies that Sj’s own request is at the top of its own request_queue when a smaller
timestamp request, Si’s request, is present in there quest_queuej – a contradiction!!
Hence, Lamport’s algorithm achieves mutual exclusion.

Theorem 2: Lamport’s algorithm is fair.


Proof:
 A distributed mutual exclusion algorithm is fair if the requests for CS are executed in
the order of their timestamps. The proof is by contradiction.
 Suppose a site Si’s request has a smaller timestamp than the request of another site Sj
and Sj is able to execute the CS before Si. For Sj to execute the CS, it has to satisfy the
conditions L1 and L2.
 This implies that at some instant in time say t, Sj has its own request at the top of its
queue and it has also received a message with timestamp larger than the timestamp of
its request from all other sites.
 But request_queueat a site is ordered by timestamp, and according to our assumption
Si has lower timestamp.
 So Si’s request must be placed ahead of the Sj’s request in the request_queuej .
This is a contradiction. Hence Lamport’s algorithm is a fair mutual exclusion
algorithm.
An Example
In Figures 9.3 to 9.6, we illustrate the operation of Lamport’s algorithm. In Figure 9.3, sites S1
andS2 are making requests for the CS and send out REQUEST messages to other sites. The
time stamps of the requests are (1, 1) and (1, 2), respectively. In Figure 9.4, both the sites S1
and S2 have received REPLY messages from all other sites. S1 has its request at the top of its
request_queue but site S2 does not have its request at the top of its request_queue.
Consequently, site S1 enters the CS. In Figure 9.5, S1 exits and sends RELEASE messages to

6
CS3551-DISTRIBUTED COMPUTING –UNIT 3

all other sites. In Figure 9.6, site S2 has received REPLY from all other sites and also received
a RELEASE message from siteS1. Site S2 updates its request_queue and its request is now at
thetop of its request_queue. Consequently, it enters the CS next.

7
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Performance
for each CS invocation
 (N-1) REQUEST
 (N-1) REPLY
 (N-1) RELEASE,
Total 3(N-1) messages, synchronization delay Sd = average delay.
Drawbacks of Lamport’s Algorithm:
 Unreliable approach: failure of any one of the processes will halt the progress of entire
system.
 High message complexity: Algorithm requires 3(N-1) messages per critical section
invocation.

Performance:
Synchronization delay is equal to maximum message transmission time. It requires 3(N – 1)
messages per CS execution. Algorithm can be optimized to 2(N – 1) messages by omitting the
REPLY message in some situations.
3.4. RICART-AGRAWALA ALGORITHM
The Ricart-Agrawala algorithm assumes the communication channels are FIFO.
 The algorithm uses two types of messages: REQUEST and REPLY.
 A process sends a REQUEST message to all other processes to request their permission
to enter the critical section.
 A process sends a REPLY message to a process to give its permission to that process.
 Processes use Lamport-style logical clocks to assign a timestamp to critical section
requests. Timestamps are used to decide the priority of requests in case of conflict – if
a process pi that is waiting to execute the critical section, receives a REQUEST
message from process pj, then if the priority of pj’s request is lower, pi defers the
REPLY to pj and sends a REPLY message to pj only after executing the CS for it
spending request.
 Otherwise, pi sends a REPLY message to pj immediately, provided it is currently not
executing the CS. Thus, if several processes are requesting execution of the CS, the

8
CS3551-DISTRIBUTED COMPUTING –UNIT 3

highest priority request succeeds in collecting all the needed REPLY messages and gets
to execute the CS.

Each process pi maintains the Request-Deferred array, RDi, the size of which is the
same as the number of processes in the system. Initially, ∀i ∀j: RDi[j]=0. Whenever pi defer
the request sent by pj, it sets RDi[j]=1 and after it has sent a REPLY message to pj, it sets
RDi[j]=0. Note: Deferred – Postponed the request / waiting
ALGORITHM
1. Requesting the critical section:
(a) When a site Si wants to enter the CS, it broadcasts a time stamped REQUEST message to
all other sites.
(b) When site Sj receives a REQUEST message from site Si, it sends a REPLY message
to Site Si
• If site Sj is neither requesting nor executing the CS, or
• If the site Sj is requesting And Si’s request’s timestamp is smaller than site
Sj’s own request’s timestamp.
• Otherwise, the reply is deferred and Sj sets RDj[i]=1
2. Executing the critical section:
(c) Site Si enters the CS after it has received a REPLY message from every site it
sent a REQUEST message to.
3. Releasing the critical section:
(d) When site Si exits the CS, it sends all the deferred REPLY messages: ∀j
ifRDi[j]=1, then send a REPLY message to Sj and set RDi[j]=0.
When a site receives a message, it updates its clock using the timestamp in the message. Also,
when a site takes up a request for the CS for processing, it updates its local clock and assigns a
timestamp to the request. In this algorithm, a site’s REPLY messages are blocked only by
sites which are requesting the CS with higher priority (i.e., smaller timestamp).Thus, when a
site sends out differed REPLY messages, site with the next highest priority request receives
the last needed REPLY message and enters the CS. Execution of the CS requests in this
algorithm is always in the order of their timestamps.

An Example
Figures 9.7 to 9.10 illustrate the operation of Ricart-Agrawala algorithm. In Figure 9.7,
sites S1 and S2 are making requests for the CS and send out REQUEST messages to other
sites. The timestamps of the requests are (2, 1) and (1, 2), respectively. In Figure 9.8, S2 has
received REPLY messages from all other sites and consequently, it enters the CS. In Figure
9.9, S2 exits the CS and sends a REPLY message to site S1. In Figure 9.10, site S1 has
received REPLY from all other sites and enters the CS next.

9
CS3551-DISTRIBUTED COMPUTING –UNIT 3

10
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Performance
Message Complexity
For each CS execution, Ricart-Agrawala algorithm requires
 (N − 1) REQUEST messages and
 (N−1) REPLY messages.
Thus, it requires 2(N−1) messages per CS execution. Synchronization
delay in the algorithm is T.
3.5 TOKEN BASED ALGORITHMS
 A unique token (also known as the PRIVILEGE message) is shared among the
sites.
 A site is allowed to enter its CS if it possesses the token and it continues to hold the
token until the execution of the CS is over.
 Mutual exclusion is ensured because the token is unique.
 Example:Suzuki-Kasami’s Broadcast Algorithm.

3.6 SUZUKI-KASAMI’S BROADCAST ALGORITHM


 Suzuki–Kasami algorithm is a token-based algorithm for achieving mutual exclusion
in distributed systems.
 This is modification of Ricart–Agrawala algorithm, a permission based (Non-token
based) algorithm which uses REQUEST and REPLY messages to ensure mutual
exclusion.
 In token-based algorithms, A site is allowed to enter its critical section if it possesses
the unique token.
 Non-token based algorithms uses timestamp to order requests for the critical section
where as sequence number is used in token based algorithms.
 Each requests for critical section contains a sequence number. This sequence number
is used to distinguish old and current requests.
Data structures used in SK algorithm

 R [1...n] - request queue maintained at each site Si of size n each index corresponds to
every other site of OS.
 T[n] - token array of size n to maintain the number of times the particular site
requested the token.
 Q - Token request queue consists of the site IDs of simultaneous requests from
different sites.
Messages:

 REQUEST(i,n) - site Si request for token for nth time.


 PREVILEDGE(T) - granting token message

11
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Suzuki–Kasami‘s broadcast algorithm:

To enter Critical section:


 When a site Si wants to enter the critical section and it does not have the token then
it increments its sequence number RNi[i] and sends a request message
REQUEST(i, sn) to all other sites in order to request the token.Here sn is update
value of RNi[i])
 When a site Sj receives the request message REQUEST(i, Sn) from site Si, it
sets RNj[i] to maximum of RNj[i] and sni.eRNj[i] = max(RNj[i], Sn).
After updating RNj[i], Site Sj sends the token to site Si if it has token and RNj[i]
=LN[i] + 1
To execute the critical section:
 Site Si executes the critical section if it has acquired the token.
To release the critical section:
After finishing the execution Site Si exits the critical section and does following:
 sets LN[i] = RNi[i] to indicate that its critical section request RNi[i] has been executed
 For every site Sj, whose ID is not prsent in the token queue Q, it appends its ID to Q
ifRNj[j] = LN[j] + 1 to indicate that site Sj has an outstanding request.
 After above updation, if the Queue Q is non-empty, it pops a site ID from the Q
andsends the token to site indicated by popped ID.
 If the queue Q is empty, it keeps the token.

1. How to distinguishing an outdated REQUEST message from a current REQUEST
message:
Due to variable message delays, appropriate mechanisms should implemented to determine if a
token request message is outdated.
When a site SJ receives a REQUEST(i , n) message, the request is
outdated if Rj [i]>n.

2. How to determine which site has an outstanding request for the CS:
After a site has finished the execution of the CS, it must determine what sites have an
outstanding request for the CS so that the token can be dispatched to one of them.
Finally, the site sends the token to the site whose id is at the head of the Q.
At site Si if Ri [j]=T[j]+1, then site Sj is currently requesting token.

Correctness
Mutual exclusion is guaranteed because there is only one token in the system and a site
holdsthe token during the CS execution.
Theorem: A requesting site enters the CS in finite time.
Proof: Token request messages of a site Si reach other sites in finite time.

12
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Since one of these sites will have token in finite time, site Si ’s request will be placed in the
token queue in finite time.
Since there can be at most N − 1 requests in front of this request in the token queue, site Si
will get the token and execute the CS in finite time.
Message Complexity:
The algorithm requires 0 message invocation if the site already holds the idle token at the
time of critical section request or maximum of N message per critical section execution.
This N messages involves
 (N – 1) request messages
 1 reply message

Drawbacks of Suzuki–Kasami Algorithm:


 Non-symmetric Algorithm: A site retains the token even if it does not have
requestedfor critical section.

Performance:
Synchronization delay is 0 and no message is needed if the site holds the idle token at
the time of its request. In case site does not holds the idle token, the maximum
synchronizationdelay is equal to maximum message transmission time and a maximum
of N message is required per critical section invocation.
Example:
Initial State:

S1 want to enter into critical section and broadcast token request REQUEST(1,1):

13
CS3551-DISTRIBUTED COMPUTING –UNIT 3

On Receiving S1 Request:

1. Check for Outdated request


R2[1]=0 and n=1
n>R2[1],So not an outdated request
2.Determining Outstanding Request
R2[1]=T+1
1=1+0 =>1

Granting token:

14
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Site S1 on Completing CS:

Next S3 and S4 Simultaneously requesting CS:

15
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Granting Token:

16
CS3551-DISTRIBUTED COMPUTING –UNIT 3

Site S3 on completing CS:

17
CS3551-DISTRIBUTED COMPUTING – UNIT 3

3.6. DEADLOCK DETECTION IN DISTRIBUTED SYSTEMS: INTRODUCTION


 Deadlocks are a fundamental problem in distributed systems.
 “A deadlock can be defined as a condition or Situation where a set of processes request
resources that are held by other processes in the set.”
 A process may request resources in any order, which may not be known a priori and a process
can request resource while holding others.
 If the sequence of the allocations of resources to the processes is not controlled, deadlocks
can occur.
 Deadlock deals with various components like deadlock prevention, deadlock avoidance
and deadlock detection.
 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 hold the needed resource.
 In the deadlock avoidance approach to distributed system, a resource is granted to a
process if the resulting global system is safe.
 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.
We can consider two types of deadlock:
1. Communication deadlock occurs when process A is trying to send a message to
process B, which is trying to send a message to process C which is trying to send a
message to A.
2. A resource deadlock occurs when processes are trying to get exclusive access to
devices, files, locks, servers, or other resources. We will not differentiate between
these types of deadlock since we can consider communication channels to be
resources without loss of generality.

3.7. SYSTEM MODEL


 A distributed system consists of a set of processors that are connected by a
communication network.
 The communication delay is finite but unpredictable.
 A distributed program is composed of a set of n asynchronous processes p1, p2, . . . ,
pi, . . . , pn that communicates by message passing over the communication network.
 Without loss of generality we assume that each process is running on a different
processor.
 The processors do not share a common global memory and communicate solely by
passing messages over the communication network.
 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.
 The system can be modelled as a directed graph in which vertices represent the
CS3551-DISTRIBUTED COMPUTING – UNIT 3
processes and edge represent unidirectional communication channels.
We make the following 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.
A process can be in two states: running or blocked. In the running state (also called active
state), a process has all the needed resources and is either executing or is ready for execution. In
the blocked state, a process is waiting to acquire some resource.
Wait-For-Graph (WFG)
 In distributed systems, the state of the system can be modelled by directed graph,
called a wait for graph (WFG).
 In a WFG, nodes are processes and there is a directed edge from node P1 to mode P2 if
P1 is blocked and is waiting for P2 to release some resource.
 A system is deadlocked if and only if there exists a directed cycle or knot in the WFG.
Figure 10.1 shows a WFG, where process P11 of site 1 has an edge to process P21 of site 1
and P32 of site 2 is waiting for a resource which is currently held by process P21. At the same
time process P32 is waiting on process P33 to release a resource. If P21 is waiting on process
P11, then processes P11, P32 and P21 form a cycle and all the four processes are involved in a
deadlock depending upon the request model.

3.8. PRELIMINARIES
Deadlock Handling Strategies
There are three strategies for handling deadlocks,
1. Deadlock Prevention,
2. Deadlock Avoidance,
3. Deadlock Detection.
Handling of deadlock becomes highly complicated in distributed systems because no
site has accurate knowledge of the current state of the system and because every inter
site communication involves a finite and unpredictable delay.
CS3551-DISTRIBUTED COMPUTING – UNIT 3

Deadlock prevention
 It is commonly achieved either by having a process acquire all the needed resources
simultaneously before it begins executing or by pre-empting a process which holds the
needed resource.
 This approach is highly inefficient and impractical in distributed systems.
deadlock avoidance
 A resource is granted to a process if the resulting global system state is safe (note that a
global state includes all the processes and resources of the distributed system).
 However, due to several problems, deadlock avoidance is impractical in distributed
systems.
Deadlock Detection
Issues in Deadlock Detection
Deadlock handling using the approach of deadlock detection entails addressing two basic issues:
1. Detection of existing deadlocks
2. Resolution of detected deadlocks.
1. Detection of Existing Deadlocks
 Detection of deadlocks involves addressing two issues:
• maintenance of the WFG and
• Searching of the WFG for the presence of cycles (or knots).
 Since in distributed systems, 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.
 Depending upon the way WFG information is maintained and search for cycles is
carried out, there are centralized, distributed, and hierarchical algorithms for deadlock
detection in distributed systems.
Correctness Criteria:
A deadlock detection algorithm must satisfy the following two conditions:
Correctness criteria
A deadlock detection algorithm must satisfy the following two conditions:
1. Progress-No undetected deadlocks:
The algorithm must detect all existing deadlocks in finite time. In other words, after
all wait-for dependencies for a deadlock have formed, the algorithm should not wait for
any more events to occur to detect the deadlock.
2. Safety -No false deadlocks:
The algorithm should not report deadlocks which do not exist. This is also called
ascalled phantom or false deadlocks.
2. Resolution of a Detected Deadlock
 Deadlock resolution involves breaking existing wait-for dependencies between the
processes to resolve the deadlock.
CS3551-DISTRIBUTED COMPUTING – UNIT 3
 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 information is not cleaned in timely manner, it may result in detection of
phantom deadlocks.
 Untimely and inappropriate cleaning of broken wait-for dependencies is the main
reason why many deadlock detection algorithms reported in the literature are incorrect.
3.9. MODELS OF DEADLOCKS
 The models of deadlocks are explained based on their hierarchy. Distributed systems
allow many kinds of resource requests. A process might require a single resource or a
combination of resources for its execution.

Single Resource Model


 A process can have at most one outstanding request for only one unit of a resource.
 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.

Fig 3.6: Deadlock in single resource model


AND Model
 In the AND model, a passive process becomes active (i.e., its activation condition
isfulfilled) only after a message from each process in its dependent set has
arrived.
 In the AND model, a process can request more than one resource simultaneously and
CS3551-DISTRIBUTED COMPUTING – UNIT 3
the request is satisfied only after all the requested resources are granted to the
process.
 The out degree of a node in the WFG for AND model can be more than 1.
 The presence of a cycle in the WFG indicates a deadlock in the AND model.
 Each node of the WFG in such a model is called an AND node.

Fig 3.7: Deadlock in AND model


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.
 Presence of a cycle in the WFG of an OR model does not imply a
deadlockin the OR model.
 In the OR model, the presence of a knot indicates a deadlock.

Deadlock 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


dependentset.

Fig 3.8: OR Model

Model (p out of q model)


 This is a variation of AND-OR model.
 This allows a request to obtain any k available resources from a pool of n
resources.Both the models are the same in expressive power.
 This favors more compact formation of a request.
 Every request in this model can be expressed in the AND-OR model and vice-versa.
CS3551-DISTRIBUTED COMPUTING – UNIT 3

 Note that AND requests for p resources can be stated as and OR requests for
presources can be stated as

Fig 3.9: p out of q Model

Unrestricted model
 No assumptions are made regarding the underlying structure of resource requests.
 In this model, only one assumption that the deadlock is stable is made and hence it
is the most general model.
 This model helps separate concerns: Concerns about properties of the problem
(stability and deadlock) are separated from underlying distributed systems
computations (e.g., message passing versus synchronous communication).
3.10. CHANDY-MISRA-HAAS ALGORITHM FOR THE AND MODEL AND OR
MODEL.
KNAPP’S CLASSIFICATION OF DISTRIBUTED DEADLOCK DETECTION
ALGORITHMS
CS3551-DISTRIBUTED COMPUTING – UNIT 3

CHANDY–MISRA–HAAS ALGORITHM FOR THE AND MODEL

 This is considered an edge-chasing, probe-based algorithm.


 It is also considered one of the best deadlock detection algorithms for
distributedsystems.
 If a process makes a request for a resource which fails or times out, the process
generates a probe message and sends it to each of the processes holding one or
moreof its requested resources.
 This algorithm uses a special message called probe, which is a triplet (i, j,k),
denotingthat it belongs to a deadlock detection initiated for process Pi andit is being
sent by the home site of process Pj to the home site of process Pk.
 Each probe message contains the following information:
 the id of the process that is blocked (Initiator);
 the id of the process is sending this particular version of the probe
message(Sender)
 the id of the process that should receive this probe message(Receiver)
 A probe message travels along the edges of the global WFG graph, and a deadlock
isdetected when a probe message returns to the process that initiated it.
 When a process receives a probe message, it checks to see if it is also waiting
for resources
 If it is waiting for resources, it passes on the probe message to all processes it
knowsto be holding resources it has itself requested.
 The process first modifies the probe message, changing the sender and receiver ids.
 If a process receives a probe message that it recognizes as having initiated, it
knows there is a cycle in the system and thus, deadlock.
Data structures
Each process Pi maintains a boolean array, dependent i, where dependent(j) is true only if
Pi knows that Pj is dependent on it. Initially, dependenti (j) is false for all i and j.
CS3551-DISTRIBUTED COMPUTING – UNIT 3

Chandy–Misra–Haas algorithm for the AND Model

Example:
CS3551-DISTRIBUTED COMPUTING – UNIT 3
Performance analysis
 In the algorithm, one probe message is sent on every edge of the WFG
whichconnects processes on two sites.
 The algorithm exchanges at most m(n − 1)/2 messages to detect a deadlock
thatinvolves 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).

Advantages:
 It is easy to implement.
 Each probe message is of fixed length.
 There is very little computation.
 There is very little overhead.
 There is no need to construct a graph, nor to pass graph information to other sites.
 This algorithm does not find false (phantom) deadlock.
 There is no need for special data structures.

3.11. CHANDY-MISRA-HAAS ALGORITHM FOR THE OR MODEL


 Chandy-Misra-Haas distributed deadlock detection algorithm for OR model that is
based on the approach of diffusion-computation.
 A blocked process determines if it is deadlocked by initiating a diffusion computation.
 Two types of messages are used in adiffusion computation:
 query(i, j, k) and
 reply(i, j, k),
denoting that they belong to a diffusion computation initiated by a process Pi and
are being sent from process Pj to process Pk.
Basic Idea
 A blocked process initiates deadlock detection by sending query messages to all
processes in its dependent set (i.e., processes from which it is waiting to receive a
message).
 If an active process receives a query or reply message, it discards it.
 When a blocked process Pk receives a query(i, j,k) message, it takes the following
actions:

1. If this is the first query message received by Pk for the deadlock detection initiated by Pi
(called the engaging query), then it propagates the query to all the processes in its dependent set
and sets a local variable numk(i) to the number of query messages sent.

2. If this is not the engaging query, then Pk returns a reply message to it immediately provided
Pk has been continuously blocked since it received the corresponding engaging query.
Otherwise, it discards the query.
CS3551-DISTRIBUTED COMPUTING – UNIT 3
3. Process Pk maintains a boolean variable waitk(i) that denotes the fact that it has been
continuously blocked since it received the last engaging query from process Pi. When a
blocked process Pk receives a reply(i, j, k) message, it decrements numk(i) only if waitk(i)
holds.

4. A process sends a reply message in response to an engaging query only after it has received
a reply to every query message it had sent out for this engaging query

5. . The initiator process detects a deadlock when it receives reply messages to all the query
messages it had sent out.
The Algorithm:

Example: query(i, j, k)
CS3551-DISTRIBUTED COMPUTING – UNIT 3

Example for reply(i, j, k):

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

You might also like