Distributed Mutual Exclusion
Distributed Mutual Exclusion
F 6/7 - 1
Distributed Systems
F 6/7 - 2
Mutual Exclusion
2. Non-Token-Based Algorithms
3. Token-Based Algorithms
4. Distributed Election
Distributed Systems
F 6/7 - 3
Distributed Systems
Ricart-Agrawala Algorithm
F 6/7 - 4
Distributed Systems
F 6/7 - 5
Distributed Systems
F 6/7 - 6
P2
P0
P2
P1
OK
P0
release
OK
request
P2
req
ues
t
P1
P0
Queue
Queue
Queue
Coordinator
Coordinator
Coordinator
Problems
The coordinator can become a performance
bottleneck.
The coordinator is a critical point of failure:
- If the coordinator crashes, a new coordinator
must be created.
- The coordinator can be one of the processes
competing for access; an election algorithm
(see later) has to be run in order to choose one
and only one new coordinator.
Distributed Systems
F 6/7 - 7
Distributed Systems
Ricart-Agrawala Algorithm
F 6/7 - 8
F 6/7 - 9
Distributed Systems
F 6/7 - 10
req
(11 ues
,1) t
P1
request
(15,2)
request
(11,1)
P2
P1
P0
OK
P2
P1
OK
P1 gets the
resource
P2
P2 gets the
resource
Problems
P0
OK
P0
st
ue )
req15,2
(
OK
Distributed Systems
Distributed Systems
F 6/7 - 11
Distributed Systems
F 6/7 - 12
Distributed Systems
F 6/7 - 13
Distributed Systems
F 6/7 - 14
The Algorithm
Distributed Systems
i+1 i i-1
Pj
es
t
CS left and no
other request there
Pi
t
es
u
eq
Pi-1
i+1 i i-1
Pi+1
9
j
12
12 11 6
token
i+1 i i-1
Pj
pass token
10 9 9
requestPi
Pi-1
es
request
TOKEN
PRESENT
qu
st
ue
q
re
qu
10 9 9
requestPi
ues
re
re
a
requ n extern
est c
a
ome l
s in
NO
TOKEN
r
the
d o ists
n
ta x
lef st e
CS eque
r
12
12 8 6
token
req
Pi+1
st
ue
q
re
es
qu
ge
i+1 i i-1
re
TOKEN
HELD
n
oke
ts t
F 6/7 - 16
F 6/7 - 15
ue
s
Distributed Systems
re
q
Pi
Distributed Systems
F 6/7 - 17
Distributed Systems
F 6/7 - 18
Pn
P1
P2
P3
P5
Distributed Systems
F 6/7 - 19
Distributed Systems
The algorithm
P4
F 6/7 - 20
Distributed Systems
F 6/7 - 21
Distributed Systems
F 6/7 - 22
Election
Election (contd)
Distributed Systems
F 6/7 - 23
Distributed Systems
F 6/7 - 24
Distributed Systems
F 6/7 - 25
Distributed Systems
F 6/7 - 26
P5
el
P6
P7
ans
coo
rd
or
P1
coord
P6
co
P7
P5
d
coor
d
or
P4
P3
co
P5
P6
P6
P1
P2
P1
P5
el
P3
P4
P7
ans
ans
el
P4
P7
P1
P2
P3
el
P4
el
P2
P3
Distributed Systems
F 6/7 - 27
Distributed Systems
F 6/7 - 28
Distributed Systems
F 6/7 - 29
Distributed Systems
F 6/7 - 30
The Algorithm
By default, the state of a process is NON-PARTICIPANT
Rule for election process initiator
/* performed by a process Pi, which triggers the
election procedure */
[RE1]: statePi := PARTICIPANT.
[RE2]: Pi sends an election message with message.id := i
to its neighbour.
Rule for handling an incoming election message
/* performed by a process Pj, which receives an
election message */
[RH1]: if message.id > j then
Pj forwards the received election message.
statePj := PARTICIPANT.
elseif message.id < j then
if statePj = NON-PARTICIPANT then
Pj forwards an election message with
message.id := j.
statePj := PARTICIPANT
end if
else
Pj is the coordinator and sends an elected
message with message.id := j to its neighbour.
statePj := NON-PARTICIPANT.
end if.
Petru Eles, IDA, LiTH
Distributed Systems
F 6/7 - 31
Distributed Systems
Summary
15
9
10
22
5
7
22
F 6/7 - 32
Distributed Systems
F 6/7 - 33
Summary (contd)