Lamport Algorithm

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

3.

2 LAMPORT’S ALGORITHM
• Request for CS are executed in the increasing order of timestamps and time is
determined by logical clocks.
• Every site Si keeps a queue, request_queuei which contains mutual exclusion requests
ordered by their timestamps
• This algorithm requires communication channels to deliver messages the FIFO
order.Three types of messages are used Request, Reply and Release. These messages
with timestamps also updates logical clock

Fig: Lamport’s distributed mutual exclusion algorithm


To enter Critical section:
When a site Si wants to enter the critical section, it sends a request message
Request(tsi, i) to all other sites and places the request on request_queuei. Here, Tsi
denotes the timestamp of Site Si.
When a site Sj receives the request message REQUEST(tsi, i) from site Si, it returns a
timestamped REPLY message to site Si and places the request of site Si on
request_queuej

To execute the critical section:


• A site Si can enter the critical section if it has received the message with timestamp
larger than (tsi, i) from all other sites and its own request is at the top of
request_queuei.

To release the critical section:


When a site Si exits the critical section, it rSemoves its own request from the top of its request
queue and sends a timestamped RELEASE message to all other sites. When a site Sj receives the
timestamped RELEASSE message from site Si, it removes the request of Sia from its request
queue.
Fig) S1 and S2 are making requests for the CS

Fig) Site S1 enters the CS

Fig) Site S1 exists the CS and sends RELEASE messages


Fig) Site S2 enters the CS

Correctness
Theorem: Lamport’s algorithm achieves mutual exclusion.
Proof: Proof is by contradiction.
Suppose two sites Si and Sj are executing the CS concurrently. For this to happen
conditions L1 and L2 must hold at both the sites concurrently.
This implies that at some instant in time, say t, both Si and Sj have their own requests
at the top of their request queues and condition L1 holds at them. Without loss of
generality, assume that Si ’s request has smaller timestamp than the request of Sj .
From condition L1 and FIFO property of the communication channels, it is clear that
at instant t the request of Si must be present in request queuej when Sj was executing
its CS. This implies that Sj ’s own request is at the top of its own request queue
when a smaller timestamp request, Si ’s request, is present in the request queuej – a
contradiction!

Theorem: Lamport’s algorithm is fair.


Proof: The proof is by contradiction.
Suppose a site Si ’s request has a smaller timestamp than the request of another site Sj
and Sj is able to execute the CS before Si .
For Sj to execute the CS, it has to satisfy the conditions L1 and L2. This implies
that at some instant in time say t, Sj has its own request at the top of its queue and it
has also received a message with timestamp larger than the timestamp of its request
from all other sites.
But request queue at a site is ordered by timestamp, and according to our assumption
Si has lower timestamp. So Si ’s request must be placed ahead of the Sj ’s request in
the request queuej . This is a contradiction!

Message Complexity:
Lamport’s Algorithm requires invocation of 3(N – 1) messages per critical section execution.
These 3(N – 1) messages involves
• (N – 1) request messages
• (N – 1) reply messages
• (N – 1) release messages
Drawbacks of Lamport’s Algorithm:
• Unreliable approach: failure of any one of the processes will halt the progress
ofentire system.
• High message complexity: Algorithm requires 3(N-1) messages per critical
sectioninvocation.

To enter Critical section:


• When a site Si wants to enter the critical section, it send a timestamped
REQUESTmessage to all other sites.
• When a site Sj receives a REQUEST message from site Si, It sends a REPLY
message to site Si if and only if Site Sj is neither requesting nor currently executing
the critical section.

• In case Site Sj is requesting, the timestamp of Site Si‘s request is smaller than its
ownrequest.
• Otherwise the request is deferred by site Sj.

To execute the critical section:


Site Si enters the critical section if it has received the REPLY message from all other
sites.

To release the critical section:

Upon exiting site Si sends REPLY message to all the deferred requests.

Performance:
Synchronization delay is equal to maximum message transmission time. It requires 3(N –
1) messages per CS execution. Algorithm can be optimized to 2(N – 1) messages by
omitting the REPLY message in some situations.

3.3 RICART–AGRAWALA ALGORITHM


• Ricart–Agrawala algorithm is an algorithm to for mutual exclusion in a
distributedsystem proposed by Glenn Ricart and Ashok Agrawala.
• This algorithm is an extension and optimization of Lamport’s Distributed
MutualExclusion Algorithm.
• It follows permission based approach to ensure mutual exclusion.
• Two type of messages ( REQUEST and REPLY) are used and communication
channels are assumed to follow FIFO order.

• A site send a REQUEST message to all other site to get their permission to
entercritical section.
• A site send a REPLY message to other site to give its permission to enter the

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy