Ricart–Agrawala algorithm
Appearance
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.
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 Lamport 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 timestampped 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 on
- Otherwise, will defer the message.
Critical Section:
- Site enters its critical section only after receiving all replies.
- Upon exiting the critical section, sends all deferred reply 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