Prerequisite: Mutual exclusion in distributed systems
Lamport’s Distributed Mutual Exclusion Algorithm is a permission based algorithm proposed by Lamport as an illustration of his synchronization scheme for distributed systems.
In permission based timestamp is used to order critical section requests and to resolve any conflict between requests.
In Lamport’s Algorithm critical section requests are executed in the increasing order of timestamps i.e a request with smaller timestamp will be given permission to execute critical section first than a request with larger timestamp.
In this algorithm:
- Three type of messages ( REQUEST, REPLY and RELEASE) 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 enter critical section.
- A site send a REPLY message to requesting site to give its permission to enter the critical section.
- A site send a RELEASE message to all other site upon exiting the critical section.
- Every site Si, keeps a queue to store critical section requests ordered by their timestamps.
request_queuei denotes the queue of site Si
- A timestamp is given to each critical section request using Lamport’s logical clock.
- Timestamp is used to determine priority of critical section requests. Smaller timestamp gets high priority over larger timestamp. The execution of critical section request is always in the order of their timestamp.
- 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 removes 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 RELEASE message from site Si, it removes the request of Si from its request queue
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 of entire system.
- High message complexity: Algorithm requires 3(N-1) messages per critical section invocation.
- 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.
- Mutual exclusion in distributed system | Maekawa’s Algorithm
- Mutual exclusion in distributed system | Suzuki–Kasami algorithm
- Mutual exclusion in distributed system | Ricart–Agrawala algorithm
- Mutual exclusion in distributed system
- Peterson's Algorithm for Mutual Exclusion | Set 1 (Basic C implementation)
- Peterson's Algorithm for Mutual Exclusion | Set 2 (CPU Cycles and Memory Fence)
- Hierarchical Deadlock Detection in Distributed System
- Algorithm for implementing Distributed Shared Memory
- Chandy-Misra-Haas's Distributed Deadlock Detection Algorithm
- Operating System | Banker's Algorithm
- Operating System | Dekker's algorithm
- Operating System | Bakery Algorithm
- Operating System | Deadlock detection algorithm
- Operating System | Program for Next Fit algorithm in Memory Management
- Operating System | Peterson's Algorithm (Using processes and shared memory)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.