0% found this document useful (0 votes)
48 views17 pages

Lamports Algorithm

Lamport's Mutual Exclusion Algorithm is a non-token based distributed algorithm that ensures mutual exclusion by using timestamps and FIFO message delivery. It involves three main steps: requesting, executing, and releasing the critical section, with a message complexity of 3(N-1) messages per request. The algorithm is unreliable as it halts progress if any participant fails.

Uploaded by

jainaryanjain30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views17 pages

Lamports Algorithm

Lamport's Mutual Exclusion Algorithm is a non-token based distributed algorithm that ensures mutual exclusion by using timestamps and FIFO message delivery. It involves three main steps: requesting, executing, and releasing the critical section, with a message complexity of 3(N-1) messages per request. The algorithm is unreliable as it halts progress if any participant fails.

Uploaded by

jainaryanjain30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Lamport’s Mutual Exclusion Algorithm

Learning Outcome

At the end of this session,


• Students will be able to learn the working of Lamport’s Mutual
Exclusion Algorithm.

Walchand Institute of Technology, Solapur 2


Introduction
• Lamport was the first to give a distributed mutual exclusion algorithm.
• It is Non Token based Algorithm.
• It is based on Lamport's clock synchronization scheme.
• Assumes messages are delivered in FIFO order between each pair of sites.
• Every site Si keeps a queue, request_queue, each request gets a timestamp.
• Requests with lower timestamps take priority over requests with higher
timestamps.
• Each site maintains a queue of pairs (timestamp, id of site) i.e.(ts, i),
ordered by timestamp.

Walchand Institute of Technology, Solapur 3


Lamport’s Mutual Exclusion Algorithm
• Lamport’s Algorithms working is held by following sections:
1. Requesting the critical section
2. Executing the critical section
3. Releasing the critical section

Walchand Institute of Technology, Solapur 4


1.Requesting the critical section

1. When a site Si wants to enter the CS, it sends a REQUESTS, (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.)

2. 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.

Walchand Institute of Technology, Solapur 5


2. Executing the critical section

• 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_queuei.

Walchand Institute of Technology, Solapur 6


3. Releasing the critical section
1. 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.

2. When a site Sj receives a RELEASE message from site Si, it removes


Si’s request from its request queue.

Walchand Institute of Technology, Solapur 7


Example

Fig 1: Sites S1 and S2 are making requests for the CS. Ref: [1]

Walchand Institute of Technology, Solapur 8


Example…

Fig 2: Site S2 enters the CS. Ref:[1]

Walchand Institute of Technology, Solapur 9


Example…

Fig 3 : Site S2 exits the CS and sends RELEASE messages. Ref:[1]

Walchand Institute of Technology, Solapur 10


Example…

Fig 4 : Site S1 enters the CS. Ref:[1]

Walchand Institute of Technology, Solapur 11


Message Complexity

• This algorithm creates 3(N − 1) messages per request, or (N − 1) messages


and 2 broadcasts.
• 3(N − 1) messages per request includes:
- (N − 1) total number of requests
- (N − 1) total number of replies
- (N − 1) total number of releases

Walchand Institute of Technology, Solapur 12


Think and Write

Lamport’s distributed mutual exclusion algorithm will fail if one of its participants
fails.

a) True b) False

Pause video and write down your answer

Walchand Institute of Technology, Solapur 13


Think and Write

Lamport’s distributed mutual exclusion algorithm will fail if one of its


participants fails.

a) True b) False

Answer: a) True

Walchand Institute of Technology, Solapur 14


Lamport Algorithms Performance

• 3(N-1) messages per CS invocation


• Synchronisation Delay (ds) = T

Walchand Institute of Technology, Solapur 15


Lamport Algorithm’s Drawbacks

• It is very unreliable as failure of any one of the processes will halt progress.
• It has a high message complexity of 3(N − 1) messages per entry/exit into the
critical section.

Walchand Institute of Technology, Solapur 16


Thank you…

Walchand Institute of Technology, Solapur 18

You might also like