Prerequisite: Mutual exclusion in distributed systems
Ricart–Agrawala algorithm is an algorithm to for mutual exclusion in a distributed system proposed by Glenn Ricart and Ashok Agrawala. This algorithm is an extension and optimization of Lamport’s Distributed Mutual Exclusion Algorithm. Like Lamport’s Algorithm, it also follows permission based approach to ensure mutual exclusion.
In this algorithm:
- 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 enter critical section.
- A site send a REPLY message to other site to give its permission to enter the critical section.
- 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 send a timestamped REQUEST message 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 own request.
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.
Ricart–Agrawala algorithm requires invocation of 2(N – 1) messages per critical section execution. These 2(N – 1) messages involves
- (N – 1) request messages
- (N – 1) reply messages
Drawbacks of Ricart–Agrawala algorithm:
- Unreliable approach: failure of any one of node in the system can halt the progress of the system. In this situation, the process will starve forever.
The problem of failure of node can be solved by detecting failure after some timeout.
- Synchronization delay is equal to maximum message transmission time
- It requires 2(N – 1) messages per Critical section execution
- Mutual exclusion in distributed system | Lamport's Algorithm
- Mutual exclusion in distributed system | Maekawa’s Algorithm
- Mutual exclusion in distributed system | Suzuki–Kasami 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 | Bakery Algorithm
- Operating System | Banker's Algorithm
- Operating System | Dekker's 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 firstname.lastname@example.org. 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.