CST 402 - DISTRIBUTED COMPUTING
Downloaded from Ktunotes.in
Module - III
Downloaded from Ktunotes.in
Module – III
Lesson Plan
L1: Distributed mutual exclusion algorithms – System model, Lamport’s algorithm
L2: Ricart–Agrawala algorithm
L3: Quorum-based mutual exclusion algorithms – Maekawa’s algorithm
L4: Token-based algorithm – Suzuki–Kasami’s broadcast algorithm.
L5: Deadlock detection in distributed systems – System model, Deadlock
handling strategies, Issues in deadlock detection.
L6: Models of deadlocks
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
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 a mutually exclusive manner.
Mutual exclusion in a distributed system states that only one process is
allowed to execute the critical section (CS) at any given time
There are three basic approaches for implementing distributed mutual
exclusion:
1. Token-based approach.
2. Non-token-based approach
3. .Quorum-based approach.
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
In the token-based approach, a unique token 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
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.
A site enters the critical section (CS) when an assertion, defined on its local variables,
becomes true.
In the quorum-based approach, each site requests permission to execute the CS
from a subset of sites (called a quorum).
The quorums are formed in such a way that when two sites concurrently request
access to the CS, at least one site receives both the requests and this site is
responsible to make sure that only one request executes the CS at any time.
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
System model
The system consists of N sites, S1, S2, , SN . Without loss of generality, we assume
that a single process is running on each site
The process at site Si is denoted by pi.
All these processes communicate asynchronously over an underlying communication
network.
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: requesting the CS, executing the
CS, or neither requesting nor executing the CS
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
In the “requesting the CS” state, the site is blocked and cannot 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 refereed to as the idle token state.
At any instant, a site may have several pending requests for CS.
A site queues up these requests and serves them one at a time.
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
We do not make any assumption regarding communication channels if they are FIFO
or not.
This is algorithm specific. We assume that channels reliably deliver all messages,
sites do not crash, and the network does not get partitioned
Requirements of mutual exclusion algorithms
A mutual exclusion algorithm should satisfy the following properties:
1. 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.
2.Liveness property :
This property states the absence of deadlock and starvation.
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
Two or more sites should not endlessly wait for messages that 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.
3. Fairness :
Fairness in the context of mutual exclusion means that each process gets a fair
chance to execute the CS.
In mutual exclusion algorithms, the fairness property generally means that the CS
execution requests are executed in order of their arrival in the system
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
Performance metrics
The performance of mutual exclusion algorithms is generally measured by the
following four metrics:
Message complexity : This is the number of messages that are required per CS
execution by a site
Synchronization delay : After a site leaves the CS, it is the time required and
before the next site enters the CS
Response time : This is the time interval a request waits for its CS execution to be
over after its request messages have been sent out
Downloaded from Ktunotes.in
Distributed mutual exclusion algorithms
Performance metrics
Downloaded from Ktunotes.in
Lamport’s algorithm
Lamport developed a distributed mutual exclusion algorithm as an illustration of
his clock synchronization scheme
The algorithm is fair in the sense that a request for CS are executed in the order
of their timestamps and time is determined by logical clocks.
When a site processes a request for the CS, it updates its local clock and assigns
the request a timestamp.
The algorithm executes CS requests in the increasing order of timestamps.
Every site Si keeps a queue, request_queuei, which contains mutual exclusion
requests ordered by their timestamps.
This algorithm requires communication channels to deliver messages in FIFO
order.
Downloaded from Ktunotes.in
Lamport’s algorithm
Downloaded from Ktunotes.in
Ricart–Agrawala algorithm
The Ricart–Agrawala algorithm assumes that 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
Downloaded from Ktunotes.in
Ricart–Agrawala algorithm
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 its pending request.
Otherwise, pi sends a REPLY message to pj immediately, provided it is
currently not executing 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.
Downloaded from Ktunotes.in
Ricart–Agrawala algorithm
Downloaded from Ktunotes.in
Quorum-based mutual exclusion algorithms
Quorum-based mutual exclusion algorithms respresented a departure from
the trend in the following two ways:
A site does not request permission from all other sites, but only from a subset
of the sites.
This is a radically different approach as compared to the Lamport and
Ricart–Agrawala algorithms, where all sites participate in conflict resolution of
all other sites
In quorum-based mutual exclusion algorithm, a site can send out only one
REPLY message at any time.
A site can send a REPLY message only after it has received a RELEASE message
for the previous REPLY message.
Therefore, a site Si locks all the sites in Ri in exclusive mode before executing
its CS.
Downloaded from Ktunotes.in
Quorum-based mutual exclusion algorithms
Quorum-based mutual exclusion algorithms significantly reduce the message
complexity of invoking mutual exclusion by having sites ask permission from
only a subset of sites.
Since these algorithms are based on the notion of “Coteries” and “Quorums,”
we first describe the idea of coteries and quorums.
A coterie C is defined as a set of sets, where each set g ∈C is called a quorum.
The following properties hold for quorums in a coterie:
Intersection property
Minimality property
Coteries and quorums can be used to develop algorithms to ensure mutual
exclusion in a distributed environment
Downloaded from Ktunotes.in
Quorum-based mutual exclusion algorithms
A simple protocol works as follows: let “a” be a site in quorum “A.”
If “a” wants to invoke mutual exclusion, it requests permission from all sites in
its quorum “A.”
Minimality property ensures efficiency
Downloaded from Ktunotes.in
Maekawa’s algorithm
Maekawa’s algorithm was the first quorum-based mutual exclusion algorithm.
This algorithm requires delivery of messages to be in the order they are sent
between every pair of sites.
Downloaded from Ktunotes.in
Token-based algorithms
In token-based algorithms, a unique token is shared among the sites.
A site is allowed to enter its CS if it possesses the token.
A site holding the token can enter its CS repeatedly until it sends the token to
some other site.
Depending upon the way a site carries out the search for the token, there are
numerous token-based algorithms
token-based algorithms use sequence numbers instead of timestamps.
Every request for the token contains a sequence number
Downloaded from Ktunotes.in
Suzuki–Kasami’s broadcast algorithm
In Suzuki–Kasami’s algorithm if a site that wants to enter the CS does not have
the token, it broadcasts a REQUEST message for the token to all other sites.
A site that possesses the token sends it to the requesting site upon the
receipt of its REQUEST message.
If a site receives a REQUEST message when it is executing the CS, it sends the
token only after it has completed the execution of the CS
Although the basic idea underlying this algorithm may sound rather simple,
there are two design issues that must be efficiently addressed:
1. How to distinguishing an outdated REQUEST message from a current
REQUEST message
2. How to determine which site has an outstanding request for the CS
Downloaded from Ktunotes.in
Suzuki–Kasami’s broadcast algorithm
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Deadlocks are a fundamental problem in distributed systems
In distributed systems, a process may request resources in any order, which
may not be known a priori, and a process can request a resource while holding
others.
If the allocation sequence of process resources is not controlled in such
environments, deadlocks can occur.
A deadlock can be defined as a condition where a set of processes request
resources that are held by other processes in the set.
Deadlocks can be dealt with using any one of the following three strategies:
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 holds the needed resource.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
In the deadlock avoidance approach to distributed systems, 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.
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 communicate by message passing over the communication network.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
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.
There is no physical global clock in the system to which processes have
instantaneous access.
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 modeled as a directed graph in which vertices represent
the processes and edges represent unidirectional communication channels.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
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.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Wait-for graph (WFG)
In distributed systems, the state of the system can be modeled 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
node 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
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Deadlock handling strategies
There are three strategies for handling deadlocks,
deadlock prevention,
deadlock avoidance,
deadlock detection.
Handling of deadlocks 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.
Deadlock prevention is commonly achieved either by having a process acquire
all the needed resources simultaneously before it begins executing or by pre-
empting a process that holds the needed resource.
This approach is highly inefficient and impractical in distributed systems.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
In deadlock avoidance approach to distributed systems, a resource is granted to a
process if the resulting global system state is safe.
Due to several problems, however, deadlock avoidance is impractical in
distributed systems.
Deadlock detection requires an examination of the status of process– resource
interactions for the presence of cyclic wait.
Deadlock detection in distributed systems seems to be the best approach to
handle deadlocks in distributed systems.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Issues in deadlock detection
Deadlock handling using the approach of deadlock detection entails addressing
two basic issues:
detection of existing deadlocks
resolution of detected deadlocks.
Detection of deadlocks
Detection of deadlocks involves addressing two issues: maintenance of the WFG
and searching of the WFG for the presence of cycles
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.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Depending upon the way WFG information is maintained and the search for
cycles is carried out
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 a finite time.
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 that
do not exist (called phantom or false deadlocks).
In distributed systems where there is no global memory and there is no global
clock, it is difficult to design a correct deadlock detection algorithm because sites
may obtain an out-of-date and inconsistent WFG of the system.
As a result, sites may detect a cycle that never existed
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Resolution of a detected deadlock
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
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
Models of deadlocks
Distributed systems allow many kinds of resource requests.
A process might require a single resource or a combination of resources for its execution
Models of deadlocks introduces a hierarchy of request models starting with very
restricted forms to the ones with no restrictions
1. The single-resource model
The single-resource model is the simplest resource model in a distributed system, where
a process can have at most one outstanding request for only one unit of a resource.
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
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
2. The AND model
In the AND model, 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.
The requested resources may exist at different locations.
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.
3. The OR model
In the 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.
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
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.
3. The AND-OR model
A generalization of the previous two models (OR model and AND model) is the
AND-OR model.
In the 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).
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
4.
Another form of the AND-OR model is the ( p q )model (called the P-out-of-Q
model), which allows a request to obtain any k available resources from a pool of
n resources.
Both the models are the same in expressive power.
model lends itself to a much more compact formation of a request
Every request in the model can be expressed in the AND-OR model and vice-versa
Downloaded from Ktunotes.in
Deadlock detection in distributed systems
5. Unrestricted model
In the unrestricted model, no assumptions are made regarding the underlying
structure of resource requests.
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).
Downloaded from Ktunotes.in