Distributed Mutual Exclusion and Deadlock Detection in Distributed Systems
Module 4
CET3019B 2023
Course�Contents
Outline
Mutual exclusion
Distributed mutual exclusion algorithms
1. Token-based approach.
2. Non-token-based approach.
3. Quorum-based approach. => (Quorum: Subset of sites)
1. Token-based approach.
Example : Suzuki–Kasami Algorithm
Distributed mutual exclusion algorithms
1. Token-based approach.
2. Non-token-based approach.
3. Quorum-based approach. => (Quorum: Subset of sites)
2. Non-token-based approach.
Example : Ricart–Agrawala Algorithm
Distributed mutual exclusion algorithms
1. Token-based approach.
2. Non-token-based approach.
3. Quorum-based approach. => (Quorum: Subset of sites)
3. Quorum-based approach
Example : Maekawa’s Algorithm
Distributed mutual exclusion algorithms
1. Token-based approach.
2. Non-token-based approach.
3. Quorum-based approach. => (Quorum: Subset of sites)
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.
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 (the time is determined by a logical clock).
The first property is absolutely necessary and the other two properties are considered important in 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
• System throughput
This 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
Low and high load performance
Best and worst case performance
Lamport’s algorithm
Lamport’s algorithm: Working
Lamport’s algorithm: Working
Lamport’s algorithm: Working
Lamport’s algorithm: Working
Lamport’s algorithm: Working
Lamport’s algorithm :Performance
Lamport’s algorithm
Lamport’s algorithm
Req(Ts1,P3)
Req(Ts1,P3)
Queue (Ts1,P3)
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue (Ts2,P1)
Lamport’s algorithm
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Reply
Queue (Ts1,P3)
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue (Ts2,P1)
Lamport’s algorithm
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Reply
Reply
Queue (Ts1,P3)
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue (Ts2,P1)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Lamport’s algorithm
CS
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Reply
Reply
Reply
Reply
Queue (Ts1,P3)
Queue [ (Ts1,P3)]
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue (Ts2,P1)
Queue [ (Ts1,P3), �(Ts2,P3) ]
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue [ (Ts1,P3)�(Ts2,P1) ]
Lamport’s algorithm
CS
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Release(Ts1,P3)
Release(Ts1,P3)
Reply
Reply
Reply
Reply
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue (Ts2,P1)
Queue [ (Ts1,P3), �(Ts2,P3) ]
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue [ (Ts1,P3), �(Ts2,P1) ]
Queue [ (Ts1,P3)�(Ts2,P1) ]
Lamport’s algorithm
CS
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Release(Ts1,P3)
Release(Ts1,P3)
Reply
Reply
Reply
Reply
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue (Ts2,P1)
Queue [ (Ts1,P3), �(Ts2,P1) ]
Queue [(Ts2,P1)]
Queue [ (Ts2,P1) ]
Queue [(Ts2,P1)]
Queue [ (Ts1,P3)�(Ts2,P1) ]
Lamport’s algorithm
CS
CS
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Release(Ts1,P3)
Release(Ts1,P3)
Reply
Reply
Reply
Reply
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue [ (Ts1,P3), �(Ts2,P1) ]
Queue [ (Ts2,P1) ]
Queue [(Ts2,P1)]
Queue [ (Ts2,P1) ]
Queue [ (Ts1,P3)�(Ts2,P1) ]
Lamport’s algorithm
CS
CS
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Release(Ts1,P3)
Release(Ts1,P3)
Reply
Reply
Reply
Reply
Queue (Ts1,P3)
Queue [ (Ts1,P3)�(Ts2,P1) ]
Queue [ (Ts1,P3), �(Ts2,P1) ]
Queue [ (Ts2,P1) ]
Queue [(Ts2,P1)]
Queue [ (Ts2,P1) ]
Queue [ (Ts1,P3)�(Ts2,P1) ]
Release
Release
Queue [(Ts2,P3) ]
Queue [ (Ts2,P1) ]
Queue [ (Ts2,P1) ]
Lamport’s algorithm :An optimization
The Ricart–Agrawala Algorithm
The Ricart–Agrawala Algorithm
The Ricart–Agrawala Algorithm
The Ricart–Agrawala Algorithm
Requesting the critical section
Executing the critical section
Releasing the critical section
The Ricart–Agrawala Algorithm
Requesting the critical section
Executing the critical section
Releasing the critical section
The Ricart–Agrawala Algorithm
Requesting the critical section
Executing the critical section
Releasing the critical section
The Ricart–Agrawala Algorithm
CS
CS
Req(Ts1,P3)
Req(Ts2,P1)
Req(Ts2,P1)
Req(Ts1,P3)
Reply
Reply
Reply
DefferedQueue [ ]
Queue [ts2,P1]
DefferedQueue [ ]
Deferred Request Queue [ ]
DefferedQueue [ ]
DefferedQueue []
DefferedQueue [ts2,P1]
DefferedQueue []
Reply
Token-based algorithms
Token-based algorithms
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Any site that holds the token can enter into the critical section (CS)
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
A | B | C | D |
Request Number Counter Array
A
D
C
B
Suzuki–Kasami’s broadcast algorithm
Request Number Counter Array
A
D
C
B
0 | 0 | 0 | 0 |
A | B | C | D |
Suzuki–Kasami’s broadcast algorithm
Request Number Counter Array
A
D
C
B
1 | 0 | 0 | 0 |
A | B | C | D |
Suzuki–Kasami’s broadcast algorithm
Request Number Counter Array
A
D
C
B
1 | 1 | 0 | 0 |
A | B | C | D |
Suzuki–Kasami’s broadcast algorithm
Request Number Counter Array
A
D
C
B
0 | 0 | 0 | 0 |
A | B | C | D |
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
(A,1)
(Process, RequestSequenceNo)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
A
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
If D has token and executing critical section it will place the request in the queue.
A
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
If D has token and executing critical section it will place the request in the queue.
After the CS execution is over it remove from the queue add to RND[A] AND will transmit the token
A
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
If D has token and executing critical section it will place the request in the queue.
After the CS execution is over it remove from the queue add to RND[A] AND will transmit the token
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
(A,1)
(A,1)
(A,1)
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
If D has token and executing critical section it will place the request in the queue.
After the CS execution is over it remove from the queue add to RND[A] AND will transmit the token
Suzuki–Kasami’s broadcast algorithm
A
D
C
B
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 0 | 0 |
RNA
RNB
RNC
RND
Request Queue
Request Queue
Request Queue
Request Queue
A | B | C | D |
A | B | C | D |
A | B | C | D |
A | B | C | D |
RNB[A]< (A,1)
RNC[A]< (A,1)
RND[A]< (A,1)
All nodes approve
If D has token and executing critical section it will place the request in the queue.
After the CS execution is over it remove from the queue add to RND[A] AND will transmit the token
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Suzuki–Kasami’s broadcast algorithm
Deadlocks
Dealing with Deadlocks
System Model
System Model: Assumptions
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)
Wait-for graph (WFG): Example
Models for deadlock
The single-resource model
AND Model
OR model
AND – OR model
Chandy–Misra–Haas algorithm :AND Model
Chandy–Misra–Haas algorithm :AND Model
Chandy–Misra–Haas’s OR model
Recovery from Distributed Deadlock
Possible methods for recovery:�
There must also be an assurance that the rolled back process is not holding the resources needed by the other deadlocked processes at that point. With an appropriately chosen victim process, needed resources will be released and assigned to the other deadlocked processes. This should resolve the deadlock.
Issues in recovery methods:
What needs to be done?
Consensus and agreement algorithms
Problem definition
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
Failure models
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
Synchronous/asynchronous communication
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
Network connectivity
The system has full logical connectivity, i.e., each process can communicate with any other by direct message passing.
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
Sender identification
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
Channel reliability
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
(i) it can forge the message and claim that it was received from another process, and
(ii) it can also tamper with the contents of a received message before relaying it.
Authenticated vs. non-authenticated messages
study of agreement algorithms: assumptions
Failure models
Synchronous/asynchronous communication
Network connectivity
Sender identification
Channel reliability
Authenticated vs. non-authenticated messages
Agreement variable
Agreement variable
Byzantine Problem
Byzantine Problem Example
The Byzantine agreement problem
Validity
Byzantine
The consensus problem
The interactive consistency problem
Si
Sj
Sk
Sl
Sm
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
3:00 PM
Si
Sj
Sk
Sl
Sm
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
3:00 PM
3:00 PM
3:00 PM
3:00 PM
3:00 PM
| | | | |
3:02 PM
3:03 PM
3:04 PM
3:04 PM
Si
Sj
Sk
Sl
Sm
| | | | |