DC Module3 Notes
DC Module3 Notes
MODULE: 3
➢ There are three basic approaches for implementing distributed mutual exclusion:
1. Token-based approach.
2. Non-token-based approach.
3. Quorum-based approach
1. Token-Based Approach
➢ Unique token (PRIVILEGE message) shared among sites.
➢ A site can enter its Critical Section (CS) only if it possesses the token and holds it
until CS execution is over.
➢ Mutual exclusion ensured by the uniqueness of the token.
➢ Example: Token Ring algorithm, where a token circulates among the sites in a logical
ring fashion.
2. Non-Token-Based Approach
➢ A site enters the critical section (CS) when an assertion, defined on its local variables,
becomes true.
3. Quorum-based Approach
➢ Each site requests permission to execute the CS from a subset of sites, called a
quorum.
1
Token Based Algorithm Non-Token Based Algorithm
Uses token to enter into Critical No token is required to enter into
section critical section
Uses sequence number to execute thecritical
Uses timestamps to enter the criticalsection
section
Every request has a sequence number to Every request has a timestamp toenter
enter the critical section the critical section
Higher sequence number will be Higher the timestamp, lower the
having the lowest priority priority
Example: Suzuki-kasami’s broadcast
Example: Ricart-agrawal’s algorithm
algorithm
1. Safety property:
❖ 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.
❖ Two or more sites should not endlessly wait for messages that will never
arrive.
2
❖ Every requesting site should get an opportunity to execute the CS in finite
time.
3. Fairness:
❖ 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.
The safety property is absolutely necessary and the liveness & Fairness properties are
considered important in mutual exclusion algorithms.
Performance metrics
System throughput = 1
SD+E
3
Low and high load performance
➢ 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.
4
Lamport’s algorithm
Example:
➢ Sites S1 and S2 are making requests for the CS and send out REQUEST messages to
other sites.
➢ The timestamps of the requests are (1,1) and (1,2), respectively.
➢ Both the sites S1 and S2 have received REPLY messages from all other sites.
➢ Site 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.
➢ Site S1 enters the CS.
5
➢ S1 exits and sends RELEASE messages to all other sites.
➢ Site S2 has received REPLY from all other sites and also received a RELEASE message
from site S1.
➢ Site S2 updates its request_queue and its request is now at the top of its request_queue.
➢ It enters the CS next.
Performance
➢ For each CS execution, Lamport’s algorithm requires:
❖ N −1 REQUEST messages
❖ N −1 REPLY messages
❖ N −1 RELEASE messages
➢ Thus, Lamport’s algorithm requires 3N − 1 messages per CS invocation.
6
➢ The synchronization delay in the algorithm is T.
Advantages
➢ Simplicity
➢ Fairness
➢ Scalability
➢ Compatibility
Disadvantages
➢ Message Overhead
➢ Delayed Execution
➢ Limited Performance
➢ No Fault Tolerance
Ricart–Agrawala algorithm
7
Example
➢ Sites S1 and S2 are each making requests for the CS and sending out REQUEST
messages to other sites.
➢ The timestamps of the requests are (1,1) and (1,2), respectively.
➢ S1 has received REPLY messages from all other sites and enters the CS.
8
➢ Site S2 has received REPLY from all other sites and enters the CS next.
Performance
➢ For each CS execution, the Ricart– Agrawala algorithm requires:
❖ N − 1 REQUEST messages and
❖ N − 1 REPLY messages.
➢ Thus, it requires 2N −1 messages per CS execution.
➢ The synchronization delay in the algorithm is T.
Advantages
➢ Low Message complexity
➢ Scalability
➢ Non Blocking
Drawback
➢ Unreliable Approach
9
2. Minimality property:
❖ There should be no quorums g, h in coterie C such that g ⊇ h.
❖ For example, sets {1,2,3} and {1,3} cannot be quorums in a coterie.
➢ Coteries and quorums can be used to develop algorithms to ensure mutual
exclusion in a distributed environment.
➢ Due to the Intersection property, quorum “A” contains at least one site that is
common to the quorum of every other site.
➢ These common sites send permission to only one site at any time.
➢ Thus, mutual exclusion is guaranteed.
➢ Minimality property ensures efficiency rather than correctness.
Maekawa’s Algorithm
Requesting the critical section:
(a) A Site Si requests access to the CS by sending REQUEST(i) messages to all sites in its
request set Ri.
(b) When a Site Sj receives the REQUEST(i) message, it sends a REPLY(j) message to Si.
Otherwise, it queues up the REQUEST(i) for later consideration.
Executing the critical section:
(c) Site Si executes the CS only after it has received a REPLY message from every site in
Ri.
Releasing the critical section:
(d) After the execution of the CS is over, Site Si sends a RELEASE(i) message to every
site in Ri.
(e) When a Site Sj receives a RELEASE(i) message from Site Si, it sends a REPLY
message to the next site waiting in the queue and deletes that entry from the queue.
10
Performance
➢ For each CS execution, this algorithm requires:
❖ √N request messages
❖ √N reply messages
❖ √N release messages
➢ Requires invocation of 3√N messages per critical section execution.
➢ Synchronization delay is equal to twice the message propagation delay time.
Advantages
➢ Low message complexity
➢ Fairness
➢ Scalability
Disadvantages
➢ High overhead
➢ Limited Flexibility
➢ Delayed Execution
11
➢ This data structure is used by the token to keep record of ID of sites waiting for
the token.
Example:
❖ There are 4 sites in the distributed environment S1, S2, S3 and S4.
❖ S3 is the initial state of the system.
❖ Currently, S2 holds the token.
❖ Since the number of sites is 4, the Request array & Token array of size is 4, i.e.
R1[0,0,0,0], R2[0,0,0,0], R3[0,0,0,0], R4[0,0,0,0] & T [0,0,0,0].
❖ S1 wants to enter the Critical section & broadcasts token request REQUEST (1,1).
❖ On starting the broadcast, S1 updates its Request Array with 1.
12
REQUEST(1,1)
❖ On receiving S1’s request, the conditions have to be checked.
1. Check for outdated request
R2[1] =0 & n=1
n > R2[1]
i.e, (1>0)
So, not an outdated request.
R3[1,0,0,0]
13
❖ After S1 completing the Critical Section, the token Array is updated and the queue is
emptied.
Q= [S3, S4]
14
❖ Now the token is issued to S3.
❖ After S3 completing the Critical Section, it sets T3=R3 and queue top is deleted.
Performance
➢ Synchronization delay is 0.
➢ 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,
❖ maximum synchronization delay = maximum message transmission time
15
❖ a maximum of N message is required per critical section invocation.
➢ This N messages involves:
❖ (N – 1) request messages
❖ 1 reply message
Drawback
➢ Non-symmetric Algorithm
16
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 node P2, if
P1 is blocked and 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 shows a WFG, where process P11 of site 1 has an edge to process P21 of site
1 and an edge to process P32 of site 2.
➢ Process P32 of site 2 is waiting for a resource that is currently held byprocess P33
of site 3.
➢ At the same time process P21 at site 1 is waiting on process P24 at site 4to release a
resource, and so on.
➢ If P33 starts waiting on process P24, then processes in the WFG areinvolved in
a deadlock depending upon the request model.
17
2. Deadlock avoidance
➢ A resource is granted to a process if the resulting global system state is safe.
➢ Global state includes all processes and resources of the distributed system.
➢ Due to several problems, deadlock avoidance is impractical in distributed systems.
3. 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.
18
➢ If this information is not cleaned in a timely manner, it may result in detection of
phantom deadlocks.
5. Unrestricted model
Deadlock
Deadlock
19
➢ Consider process P44, it is not a part of any cycle but is still deadlocked as it is
dependent on P24, which is deadlocked.
3. 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.
➢ In the OR model, the presence of a knot indicates a deadlock.
➢ With every blocked process, there is an associated set of processes called dependent
set.
➢ A process shall move from an idle to an active state on receiving a grant message from
any of the processes in its dependent set.
Not deadlocked
Requesting Resources
Granting Resources
➢ The process P11 is not deadlocked because once process P33 releases its resources, P32
shall become active as one of its requests is satisfied.
➢ After P32 finishes execution and releases its resources, process P11 can continue with
its processing.
20
resource request.
➢ For example, in the AND-OR model, a request for multiple resources can be of the form
x and (y or z).
➢ To detect the presence of deadlocks in such a model, there is no familiar construct of
graph theory using WFG.
➢ A deadlock in the AND-OR model can be detected by repeated application of the
test for OR-model deadlock.
➢ However, this is a very inefficient strategy.
P
5. q Model (p out of q model)
p
6. 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.
**************************************************
21