Module 3 - Mutual Exclusion and Deadlock Detection - Sreerag Sanilkumar
Module 3 - Mutual Exclusion and Deadlock Detection - Sreerag Sanilkumar
detection
Introduction
Mutual exclusion: Concurrent access of processes to a shared resource or data is
executed in mutually exclusive manner.
Only one process is allowed to execute the critical section (CS) at any given time.
In a distributed system, shared variables (semaphores) or a local kernel cannot be used
to implement mutual exclusion.
Message passing is the sole means for implementing distributed mutual exclusion.
Distributed mutual exclusion algorithms must deal with unpredictable message delays
and incomplete knowledge of the system state.
Token-based approach
A unique token is shared among the sites.
A site is allowed to enter its CS if it possesses the token.
Mutual exclusion is ensured because the token is unique.
Performance Metrics
The performance of mutual exclusion algorithms is generally measured by the following four
metrics:
1. Message complexity : This is the number of messages that are required per CS
execution by a site
2. Synchronization delay : After a site leaves the CS, it is the time required and before
the next site enters the CS
3. 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
4. System throughput : This is the rate at which system execute request for CS. If SD is
the synchronization delay and E is the average critical section execution time, then the
throughout is given by the following equation
1
System throughput =
(SD + E)
Lamport’s Algorithm
Requests for CS are executed in the increasing order of timestamps and time is
determined by logical clocks.
Every site Si keeps a queue, request queue i , which contains mutual exclusion
requests ordered by their timestamps.
This algorithm requires communication channels to deliver messages the FIFO order.
L1: Si has received a reply message with timestamp larger than (tsi, i) from all other
sites.
L2: Si’s request is at the top of request _queue i.
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.
1. A site does not request permission from all other sites, but only from a subset of the
sites. Consequently, every pair of sites has a site which mediates conflicts between that
pair.
2. 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.
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.
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.
Maekawa’s Algorithm
Maekawa’s algorithm was the first quorum-based mutual exclusion algorithm.
The Algorithm
A site Si executes the following steps to execute the CS.
Token-based algorithm
Suzuki–Kasami’s broadcast algorithm
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.
Token-based algorithms use sequence numbers instead of timestamps. (Used to
distinguish between old and current requests.)
If a site wants to enter the CS and it does not have the token, it broadcasts a REQUEST
message for the token to all other sites.
A site which 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.
This algorithm must efficiently address the following two design issues :
A REQUEST message of site Sj has the form REQUEST(j, n) where n (n=1,2, ...) is a
sequence number which indicates that site Sjis requesting its nth CS execution.
A site Si keeps an array of integers RNi[1..N] where RNi[j] denotes the largest sequence
number received in a REQUEST message so far from site Sj.
When site Si receives a REQUEST(j , n) message, it sets RNi [j]:=max(RNi[j], n).
When a site Si receives a REQUEST(j, n) message, the request is outdated if RNi[j]>n.
The Algorithm
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.
Without loss of generality we assume that each process is running on 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.
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.
Detection of Deadlocks
Detection of deadlocks involves addressing two issues: Maintenance of the WFG and
searching of the WFG for the presence of cycles (or knots).
Correctness Criteria: A deadlock detection algorithm must satisfy the following two
conditions:
Progress (No undetected deadlocks)
The algorithm must detect all existing deadlocks in finite time.
Safety (No false deadlocks)
The algorithm should not report deadlocks which do not exist (called phantom
or false deadlocks).
Models of Deadlocks
Distributed systems allow several kinds of resource requests.
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.
Presence of a cycle in the WFG of an OR model does not imply a deadlock in the OR
model.
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.
Unrestricted Model
In the unrestricted model, no assumptions are made regarding the underlying structure of
resource requests.