Documente Academic
Documente Profesional
Documente Cultură
Msc Programme
Introduction to Distributed Mutual Exclusion
page 1
Objectives
page 2
Motivation
distributed systems
page 3
Motivation
consistency
- This is the critical section problem known from operating systems
- The problem is not solved by local kernel facilities in distributed systems
- Why is this so?
Token-Based Algorithms
Permission-Based Algorithms
Special Case
page 5
Token-Based Algorithms
between processes
The process releases the token after finishing accessing the shared
resource
page 6
Token-Based Algorithms
Advantages:
- Guarantees mutual exclusion
- Ensures starvation does not occur
- Deadlock avoidance
Disadvantages:
- If the token is lost (e.g., due to system crash), an intricate distributed
procedure needs to be started to ensure that:
page 7
Permission-Based Algorithms
- The idea was first expressed by Ricart and Agrawala in 1981
- Basic principle:
To enter a critical section, a process asks the others for permission
page 8
Permission-Based Algorithms
Properties:
- The safety property is ensured by obtaining a sufficient number of permissions
Mutual exclusion is guaranteed
The liveliness property implies freedom from both deadlock & starvation
page 9
Permission-Based Algorithms
- In the case of a central coordinator, the token-based and permission-
based approaches meet
- Processes ask only the coordinator for permission before entering the
critical section
page 10
Central Server Algorithm
0 1 2
Request OK
0 1 2
Request
no reply
0 1 2
Release
OK
coordinator 3
- It is fair
Requests are granted in the order in which they are received
No process ever wait forever (no starvation)
page 15
Central Server Algorithm
Disadvantages
- The coordinator represents a single point of failure
- A single coordinator can be a performance bottleneck
page 16
Ring-Based Algorithm
P1
- N processes are arranged in a logical ring
P2
Pn
P3 - Each process p has a communication
channel to the next process in the ring
P(i+1) mod N
P4
token
page 17
Ring-Based Algorithm
Advantages
page 18
Ring-Based Algorithm
Disadvantages
page 19
Ricard and Agrawala Algorithm
Specification
- The network consists of a set P of N processes
P = P union {pi}, i = 1 to N
unique id
page 20
3. Receiving a REPLY message (and processing it)
Ricard and Agrawala Algorithm
Approach
- A process enters its critical section after:
all processes within the system have been notified of the request and
page 21
Ricard and Agrawala Algorithm
Invoking mutual exclusion
- A process makes an attempt to invoke mutual exclusion by broadcasting a
REQUEST message to all other processes in the system
- Each requested process either sends a REPLY or defers until it leaves its
own critical section
page 22
Example
REQUEST
3
3 REPLY
1
1
1 1
1
1 2
1 2 1
a) b)
Fig a)
Fig b)
1. Before either message arrives, process 2 wishes to enter its critical section
2. Process 2 increments the clock to 1 and multicasts a REQUEST to 1 and 3
page 23
Example
REQUEST
3
3 REPLY
1 1 1
1 2 2
1 1
1 2
1 2 1
1
c) d)
Fig c)
Fig d)
2 1
1 2 1 2 2
1
e) f)
Fig e)
Fig f)
page 25
Example
REQUEST
3 3
1 1 REPLY
2 1 2 1
2 2
1 2 1 2
g) h)
Fig g)
1. Processes 1 and 3 have received their REPLY messages from 2, but not from
each other
2. Process 3’s request has arrived at 1; a REPLY is immediately send since it has
lower timestamp value
Fig h)
1. Process 3 enters its critical section after receiving all REPLY messages
page 26
Example
REQUEST
3 3
REPLY
2 1 2
2 2
1 2 1 2
i) j)
Fig i)
1. Process 3 has finished its critical section and returns the deferred REPLY
message to process 1
Fig j)
1. Process 1 enters its critical section after receiving all REPLY messages
2. After finishing the critical section processing, it does nothing since it knows no
other processing wishing to enter the critical section
page 27
Ricard and Agrawala Advantages
Mutual exclusion is achieved
- No pair of processes is ever simultaneously in its critical section
Deadlock is impossible
- Deadlock occurs when there is no process in its critical section and no
requesting process can ever proceed to its own critical section
Starvation is impossible
- Occurs if one or more processes must wait indefinitely to enter its critical
section even though others enter and exit their own critical section
Message Traffic
- The algorithm requires only 2*(N-1) message exchanges for entering
the critical section
page 28
Ricard and Agrawala Disadvantages
processes
page 29
Suzuki Kasami Algorithm
Overview
- When process Pi wants to enter its critical section (CS), it broadcasts a
REQUEST message containing its own ID as well as a sequence number n
- A process which holds the token (called PRIVILEGE message) and has left
its CS sends the token to a process still waiting for the token in the queue
page 30
Design Challenges
2. How to determine the process with outstanding request for the CS?
- A process must be able to determine which processes have outstanding
requests in order that it can send the token to one of them
page 31
Requesting the CS
If a process wants to enter the CS, it must first acquire the token by
process
- However, if it is in the CS, it gets to finish before sending the token
A process holding the token can continuously enter the CS until the page 32
Data Structures
Request vector RNi[j] at process Pi
RNi[j] contains the largest sequence number received from process j
page 33
Requesting the CS
If Pi wants to enter the CS and does not have the token, it:
page 34
Receiving a Request
- If process Pj has the token and is not in CS (i.e., is not using token),
and if RNj[i] == LN[i] + 1
page 35
Executing a Request
A process enters the CS when it acquires the token
It can keep the token provided no one requests for it, thus repeatedly
enter the CS
page 36
Releasing the Token
page 38
Evaluation
page 39
Advantages
Guarantees mutual exclusion
Is deadlock free
Is starvation free
page 40
Disadvantages
page 41
Example (taken from Internet)
Req REQUEST
req=[1,0,0,0,0] req=[1,0,0,0,0]
LN=[0,0,0,0,0] 1
0
2 req=[1,0,0,0,0]
4
req=[1,0,0,0,0] 3
req=[1,0,0,0,0]
initial state
page 42
Example
req=[1,1,1,0,0]
req=[1,1,1,0,0]
LN=[0,0,0,0,0] 1
0
2 req=[1,1,1,0,0]
4
req=[1,1,1,0,0] 3 req=[1,1,1,0,0]
page 43
Example
req=[1,1,1,0,0]
LN=[1,0,0,0,0] req=[1,1,1,0,0]
1
Q=(1,2)
0
2
req=[1,1,1,0,0]
4
req=[1,1,1,0,0] 3
req=[1,1,1,0,0]
0 prepares to exit CS
page 44
Example
req=[1,1,1,0,0]
req=[1,1,1,0,0] LN=[1,0,0,0,0]
1
Q=(2)
0
2
req=[1,1,1,0,0]
4
req=[1,1,1,0,0] 3
req=[1,1,1,0,0]
req=[2,1,1,1,0]
req=[2,1,1,1,0] LN=[1,0,0,0,0]
1
Q=(2,0,3)
0
2
req=[2,1,1,1,0]
4
req=[2,1,1,1,0] 3
req=[2,1,1,1,0]
req=[2,1,1,1,0]
req=[2,1,1,1,0]
1
0
2
req=[2,1,1,1,0]
4 LN=[1,1,0,0,0]
req=[2,1,1,1,0] Q=(0,3)
3
req=[2,1,1,1,0]
1 sends token to 2
page 47
References
Dijkstra, E.W. (1968) Cooperating Sequential Processes. Programming
Languages.