Mutual Exclusion Complete
Mutual Exclusion Complete
Synchronization Time
delay
Request
CS Request sent Enter CS Exit CS
arrives
E Time
Response Time
12
Distributed Mutual Exclusion ...
❖ Performance under Low and High Load
Performance of mutual exclusion algorithms in distributed systems can vary based
on the load conditions under two special loading conditions, viz., “low load”
and “high load”.
low load (few requests for the critical section) and high load (many
concurrent requests).
▪ The load is determined by the arrival rate of CS execution requests.
▪ Under low load conditions, there is rarely 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.
13
General System Model
14
1. Centralized Algorithm
Token-passing Algorithms
Token-passing Algorithms
Suzuki-Kasami algorithm
❖ If a site wants to enter the CS and it does
not have the token, it broadcasts a
REQUEST message for the token to all
other sites.
❖ A site which possesses the token, sends it
to the requesting site upon the receipt of its
REQUEST message.
❖ If a site receives a REQUEST message
when it is executing the CS, it sends the
token only after it has completed the
execution of the CS
I want to enter
CS I want to enter
CS
67
Suzuki-Kasami Algorithm
68
Suzuki-Kasami Algorithm
When a process j receives a request (k, num) from
process k, it sets req[k] to max(req[k], num).
Suzuki-Kasami’s algorithm
{Program of process j}
Initially, ∀i: req[i] = last[i] = 0
* Entry protocol *
req[j] := req[j] + 1
num := req[j]
Send (j, num) to all
Wait until token (Q, last) arrives
Critical Section
* Exit protocol *
last[j] := req[j]
∀k ≠ j: k ∉ Q ∧ req[k] = last[k] + 1 🡪 append k to Q;
if Q is not empty 🡪 send (tail-of-Q, last) to head-of-Q fi
Example
req=[0,0,0,0,0] req=[0,0,0,0,0]
last=[0,0,0,0,0] 1
Q=[ ] 0
2
req=[0,0,0,0,0]
4
req=[0,0,0,0,0]
3
req=[0,0,0,0,0]
initial state
72
Example
Request (0,1)
t(
Req
0,1
)
uest
2
(0,1
req=[1,0,0,0,0]
)
4
req=[1,0,0,0,0]
3
req=[1,0,0,0,0]
Example
req=[1,1,1,0,0]
req=[1,1,1,0,0]
last=[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]
Example
req=[1,1,1,0,0]
req=[1,1,1,0,0]
last=[1,0,0,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
75
Example
req=[1,1,1,0,0]
req=[1,1,1,0,0] last=[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]
Example
req=[2,1,1,1,0]
req=[2,1,1,1,0] last=[1,1,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]
Example
req=[2,1,1,1,0]
req=[2,1,1,1,0] 1
0
2
req=[2,1,1,1,0]
last=[1,1,0,0,0]
4 Q=(0,3)
req=[2,1,1,1,0]
3
req=[2,1,1,1,0]
1 sends token to 2
78
Suzuki-Kasami’s algorithm
❖ Performance
Suzuki-Kasami’s algorithm
❖ Performance
– Average messages: 0 , if a site holds the idle token at the time of
its request; otherwise N (N − 1 REQUEST messages + 1
TOKEN message) messages needed to obtain the token i.e. per
CS invocation, where N denotes the number of processes.
– Synchronization delay: 0, if a site holds the idle token at the time
of its request; otherwise T, where T denotes the average message
propagation delay.
– Disadvantage: Requires broadcast. Therefore, message overhead
is high.
Suzuki-Kasami’s algorithm (Practice 80
yourself)
1. S1 request for CS
2. S3 and S4 simultaneously
requesting for CS after S1.
81
Raymond’s Algorithm
Raymond’s Algorithm
A B C D
E F G
Raymond’s Algorithm
❖ A node needs to hold information about and communicate only to its
immediate neighbouring nodes.
❖ Similar to the concept of tokens used in token-based algorithms, this
algorithm uses a concept of privilege.
❖ Only one node can be in possession of the privilege (called the privileged
node) at any time, except when the privilege is in transit from one node to
another in the form of a PRIVILEGE message.
❖ When there are no nodes requesting for the privilege, it remains in
possession of the node that last used it.
❖ A node cannot pass token to the nodes waiting in its queue until and unless it
does not hold the token.
85
Raymond’s Algorithm …
❖ The HOLDER Variables
− Each node maintains a HOLDER variable that provides information
about the placement of the privilege in relation to the node itself.
− A node stores the identity of a node that it thinks has the privilege or
leads to the node having the privilege in its HOLDER variable .
− For two nodes X and Y, if HOLDERx = Y, then we can redraw the
undirected edge between the nodes X and Y as a directed edge from X to
Y.
− For instance, if node G holds the privilege, Figure 1 can be redrawn with
logically directed edges as shown in the Figure 2.
86
Raymond’s Algorithm …
A B C D
E F G
Figure 2: Tree with logically directed edges, all pointing in a direction towards node G - the privileged node.
•The shaded node in Figure 2 represents the privileged node.
•The following will be the values of the HOLDER variables of various nodes:
HOLDERA = B
HOLDERB = C
HOLDERC = G
HOLDERD = C
HOLDERE = A
HOLDERF = B
HOLDERG = self
87
Raymond’s Algorithm …
A B C D
E F G
Figure 3: Tree with logically directed edges, all pointing in a direction towards
node B - the privileged node.
88
Raymond’s Algorithm
❖ Now suppose node B that does not hold the privilege wants to execute
the critical section.
❖ B sends a REQUEST message to HOLDERB, i.e., C, which in turn
forwards the REQUEST message to HOLDERC, i.e., G.
❖ The privileged node G, if it no longer needs the privilege, sends the
PRIVILEGE message to its neighbor C, which made a request for the
privilege, and resets HOLDERG to C.
❖ Node C, in turn, forwards the PRIVILEGE to node B, since it had
requested the privilege on behalf of B. Node C also resets HOLDERC
to B.
89
Raymond’s Algorithm
90
Raymond’s Algorithm
❖ The value “self” is placed in REQUEST Q if the node makes a request for the
privilege for its own use.
❖ The maximum size of REQUEST Q of a node is the number of immediate
neighbors + 1 (for “self”).
❖ ASKED prevents the sending of duplicate requests for privilege, and also
makes sure that the REQUEST Qs of the various nodes do not contain any
duplicate elements.
91
Raymond’s Algorithm
92
93
94
95
Initial State
96
Now, the value of A’s holder will change from self to B and queue of A will be
empty.
Token is with B node now.
So its holder is self.
101
102
103
RQB=E
Requesting
RQD=B
104
After getting token, value of holder and queue will be changed accordingly.
Raymond’s Algorithm
❖ Performance
▪ Message overhead:- The worst-case cost = 2 x longest path length of the tree.
This happens when the privilege is to be passed between nodes at either ends
of the longest path of the minimal spanning tree. The worst possible topology
for this algorithm will be one where all nodes are arranged in a straight line. In
a straight line, the longest path length will be N-1; Thus, the number of
messages exchanged per CS execution would be 2 x (N-1).
▪ The best topology for the algorithm is the radiating star topology. Extensive
empirical measurements show that average diameter of randomly chosen trees
of size n is O(log n). The message complexity is O(diameter) of the tree.
Therefore, the average message complexity is O(log n).
107
Raymond’s Algorithm …
Suzuki-Kasami 2T+E T N N
Singhal 2T+E T N/2 N
Raymond T(log N)+E Tlog(N)/2 log(N) 4
111
Practice Question
✔ Node G (First)
✔ Node E,D (Next)
✔ Node C (immediately)
112
Practice Question
113
Practice Question
114
Practice Question
115
Practice Question
❖ C has forwarded its request bcoz, it lacks the token.
❖ C does not hold the token, so it cannot process requests in its queue.
116
Practice Question
Raymond’s algorithm
4
1
4,7
1,4
Raymond’s Algorithm
1,4 4,7
Raymond’s Algorithm
4
4
4
4,7