The Ricart-Agrawala Algorithm' is an algorithm for mutual exclusion on a distributed system. This algorithm is an extension and optimization of Lamport's Distributed Mutual Exclusion Algorithm, by removing the need for messages. It was developed by Glenn Ricart and Ashok Agrawala.
Algorithm
Terminology
- A site is any computing device which is running the Ricart-Agrawala Algorithm
- For any one request of the critical section:
- The requesting site is the site which is requesting entry into the critical section.
- The receiving site is every other site which is receiving the request from the requesting site.
- ts refers to the local timestamp of the system according to its logical clock.
Algorithm
Requesting Site:
- A requesting site sends a message to all sites.
Receiving Site:
- Upon reception of a message, the receiving site will immediately send a timestamped message if and only if:
- is not requesting or executing the critical section OR
- is requesting the critical section but sent a request with a higher timestamp than the timestamp of
- Otherwise, will defer the message.
Critical Section:
- Site enters its critical section only after receiving all messages.
- Upon exiting the critical section, sends all deferred messages.
Performance
- Number of network messages; 2*(N-1)
- Synchronization Delays: One message propagation delay
Common Optimizations
Once site has received a message from site , site may enter the critical section without receiving permission from until has sent a message to
This optimization is called Roucairol & Carvalho Optimization
Problems
One of the problems in this algorithm is failure of a node. In such a situation a process may starve forever. This problem can be solved by detecting failure of nodes after some timeout.