Distributed Mutual Exclusion
Distributed Mutual Exclusion
CS execution
time
Response Time
9
DME: A Simple Solution
Requesting the CS
When a site Si wants to enter the CS, it sends a REQUEST(tsi,i) message to all the
sites in its request set Ri and places the request on request_queuei, ((tsi, i) is the
timestamp of the request.)
When a site Sj receives the REQUEST (tsi,i) message from site Si, it returns a
timestamped REPLY message to Si and places site Si’s request on request_queuej
Executing the CS. Site Si enters the CS when the two following
conditions hold:
L1: Si has received a message with timestamp larger than (tsi, i) from all other sites.
L2: Si’s request is at the top of request_queue
Releasing the CS
Site Si, upon exiting the CS, removes its request from the top of its request queue and
sends a timestamped RELEASE message to all the sites in its request set
When a site Sj receives a RELEASE message from site Si, it removes Si’s request
from its request queue
13
DME: Lamport’s Algorithm
Correctness
Performance
Requires 3(N-1) messages per CS invocation:
(N-1) REQUEST, (N-1) REPLY, and (N-1) RELEASE messages,
Synchronization delay is T
Optimization
Can be optimized to require between 3(N-1) and 2(N-1) messages per
CS execution by suppressing REPLY messages in certain cases
E.g. suppose site Sj receives a REQUEST message from site Si after it has
sent its own REQUEST messages with timestamp higher than the
timestamp of site Si’s request
In this case, site Sj need not send a REPLY message to site Si.
14
DME: The Ricart-Agrawala
Algorithm
The token itself has got an internal FIFO-queue in order to save the
requests and an array of integers LN[1..n],
where n is the number of processes and LN[j] is the sequence number
of the request that process pj executed most recently.
Thereby it is possible to check, if a process has already been executed
So this array includes the most actual known requests of every process.
21
Requesting the critical section
If the requesting process does not have the token, it increments its sequence
number RNi[i], and sends a REQUEST(I, sn) message to all other sites
When a site Sj receives this message, it sets RNj[i] to max(RNj[i], sn). If Sj has
the idle token, then it sends the token to Si if RNj[i]=LN[i]+1
Executing the CS
Site Si executes the CS when it has received the token
Releasing the CS. Having finished the execution of the CS, site Si takes the
following actions:
It sets LN[i] element of the token array equal to RNi[i]
For everyt site Sj whose ID is not in the token queue, it appends its ID to the
token queue if RNi[j]=LN[j]+1
If token queue is nonempty after the above update, then it deletes the top site ID
from the queue and sends the token to the site indicated by the ID
22
DME: Raymond’s Tree-Based
Algorithm
Developed by Kerry Raymond in 1989
In progression:
Ricart/Agrawala : 2*(N-1) messages
Suzuki/Kasami : N messages
Maekawa : sqrt(N) messages
Raymond : log(N) messages
23
Basic Ideas
Nodes are arranged as a directed tree, such that the edges of the tree
are assigned directions toward the site (root of the tree) that has the
token
Every site has a local variable holder that points to an immediate
neighbor node on a directed path to the root node
Holder variable at sites, define logical tree structure among the sites
If we follow holder variables at sites, every site has a directed path
leading to the site holding the token
At root site, holder points to iself
Every site keeps a FIFO queue, called request_q, which stores the
request fo those neighboring sites that have sent a request to this site,
but have not yet been sent the token
24
Basic Topology
25
Algorithm
Requesting the CS
When a site wants to enter the CS, it sends a REQUEST message to the node
along the directed path to the roots, provided it does not hold the token and its
request_q is empty. It then adds its request to its request_q
When a site on the path recieves this message, it places the REQUEST in its
request_q and sends a REQUEST message along the directed path to the root
provided it has not sent out a REQUEST message on its outgoing edge
When the root site receives a REQUEST message, it sends the token to the site
from which it received the REQUEST message and sets its holder variable to
the point at that site
When a site receives the token, it deletes the top entry from its request_q, sends
the token to the site indicated in this entry, and sets its holder variable to point at
that site. If the request_q is nonempty at this point, then the site sends a
REQUEST message to the site which is pointed at by holder vairable
26
Executing the CS
A site enters the CS when it receives the token and its own entry is at
the top of its request_q.
In this case, the site deletes the top entry from its request_q and enters
the CS
Releasing the CS. After a site has finished execution of the CS, it
takes the following antions:
It its request_q is nonempty, then it deletes the top entry from its
request_q, sends the token to that site, and sets its holder variable to
point at that site
If the request_q is nonempty at this point then site sends a REQUEST
message to the site which is pointed at by the holder vairable
27
DME: Comparative
Performance Analysis
Response Time. At low loads, there is hardly any contention among requests for
the CS. Therefore, the response time under low load conditions for many algorithms
is simply a round trip message delay (= 2T) to acquire permission or token plus the
time to execute the CS (= E).
As the load is increased, response time increases in all mutual exclusion algorithms
because contention for access to the CS increases.
Synchronization Delay is the delay due to the sequential message exchanges
required after a site leaves the CS and before the next site enters the CS. In many of
algorithms, a site exiting the CS directly sends a REPLY message or the token to
the next site to enter the CS, resulting in a synchronization delay of T.
Message Traffic
When the rate of CS requests is nonuniformly distributed over sites, Singhal's
heuristic algorithm has the potential to substantially reduce the message traffic by
adapting to the prevailing system state
28
DME: Summary