Professional Documents
Culture Documents
Distributed Mutual Exclusion: Lecture Notes
Distributed Mutual Exclusion: Lecture Notes
Blank Homework
Notes Labs Scores Blank
Lecture Notes
Dr. Tong Lai Yu, March 2010
Josh Billings
1. Introduction
A Centralized Algorithm
One process is elected as the coordinator.
Whenever a process wants to access a shared-resource, it sends request
Decentralized
nontoken-based
token-based
1
S = --------
Sd + E
Sd = synchronization delay
8. Election Algorithms
Principle
Note
In many systems the coordinator is chosen by hand (e.g. file servers). This
Election by bullying
Principle
Issue
the race.
If a process doesn't get a take-over message back, it wins, and
(a) Pocess 4 holds an election. (b) Processes 5 and 6 respond, telling 4 to stop.
(c) Noew 5 and 6 hold an election. (d) Process 6 tells 5 to stop.
(e) Process 6 wins and tells everyone.
Issue
Election in a ring
Principle
coordinator.
presence known.
The initiator sends a coordinator message around the ring
containing a list of all living processes. The one with the highest
Question
Question
Lamport's Algorithm
Si -- site, N sites
Assume
messages are received in the same order as they are sent
eventually every message is received
2. When process Pj receives REQUEST(tsi, i ), it places it on its request-queuej and sends a timestamped
REPLY ( acknowledgement ) to Pi
Performance
(N-1) REPLY
(N-1) RELEASE
Example:
(a) Two processes want to access a shared resource at the same time
Voting Algorithms:
Lamport's algorithem requires a process to get permisson from all other processes. It is an overkill.
A different approach is to let processes compete for votes. If a process has received more votes than any other process, it can
enter the CS. If it does not have enough votes, it waits until the process in the CS is done and releases its votes.
Quorums have the property that any two groups have a non-empty intersection.
Simple majorities are quorums. Any 2 sets whose sizes are simple majorities must have at least one element in common.
12 nodes, so majority is 7
Grid quorum: arrange nodes in logical grid (square). A quorum is all of a row and all of a column. Quorum size is 2 √ N - 1.
Principles:
Request sets
N = { 1, 2, ..., N }
Ri ∩ Rj ≠ ∅ all i, j ∈ N
A site can send a REPLY ( LOCKED ) message only if it has not been LOCKED (i.e. has not cast the vote).
Properties:
1. Ri ∩ Rj ≠ ∅
2. Si ∈ Ri
3. |Ri| = K for all i ∈ N
4. any site Si is in K number of Ri's
N=K(K-1)+1
or K = |Ri| ≈ √N
Messages exchange:
Yield -- Y, Sj yields to Sk
( Sj has received a failed message from some other site
or Sj has sent a
yield to some other site but has not received a new grant )
Algorithm:
Example
R1 = { 1, 2, 3, 4 }
R2 = { 2, 5, 8, 11 }
R3 = { 3, 6, 8, 13 }
R4 = { 4, 6, 10, 11 }
R5 = { 1, 5, 6, 7 }
R6 = { 2, 6, 9, 12 }
R7 = { 2, 7, 10, 13 }
R8 = { 1, 8, 9, 10 }
R9 = { 3, 7, 9, 11 }
R10 = { 3, 5, 10, 12 }
R12 = { 4, 7, 8, 12 }
R13 = { 4, 5, 9, 13 }
Suppose sites 11, 8, 7 want to enter CS; they all send requests
with sequence number 1. ( 7 has highest priority, 8 next, 11 lowest )
8. 13 is locked by 11 ( has lower priority than 7 ) and receives request from 7, so it sends an
INQUIRE to 11 to ask it to yield
9. When 11 receives an INQUIRE, it knows that it cannot enter CS; therefore it
sends a YIELD to 13
10. then 13 can send L to 7 which enters CS
11. when 7 finished, sends RELEASE
12. then 8 locks all members, ... , sends RELEASE
13. then 11 enters
35. Token-based algorithms
Principles
one token, shared among all sites
site can enter its CS iff it holds token
The major difference is the way the token is searched
use sequence numbers instead of timestamps
REQUEST(j, n)
n = 1, 2, 3, ... , sequence #
node i receives REQUEST from j
TOKEN:
FCFS
Example:
Initially: the token is at p2 and the token's state is LN = [0, 0, 0] and Q empty;
p1 exits the critical section and sets the token's state to LN = [ 1, 0, 0 ] and Q = ( 3 )
p1 sends the token to p3; p1: n1 = 2, RN1 = [ 1, 0, 1 ], holding token; token's state is LN = [ 1, 0, 0 ] and Q empty
p3 exits the critical section and sets the token's state to LN = [ 1, 0, 1 ] and Q empty
Performance:
It requires at most N message exchange per CS execution ( (N-1) REQUEST messages + TOKEN message
or 0 message if TOKEN is in the site
synchronization delay is 0 or T
deadlock free ( because of TOKEN requirement )
no starvation ( i.e. a requesting site enters CS in finite time )
The essential difference is in who keeps the queue. In one case every site keeps its own local copy of the queue. In the other case, the
queue is passed around within the token.