6.2 Algorithms for Mutual Exclusion
DISTRIBUTED SYSTEM NOTES,IOE,TU,BCA
ALGORITHM FOR MUTUAL EXCLUSION
1. Lamport's Algorithm
- Idea: Uses logical clocks to order requests for the critical section.
- Mechanism:
- When a process wants to enter the critical section, it sends a timestamped request to all other processes.
- Each process maintains a request queue ordered by timestamps.
- A process can enter the critical section when its request is at the head of the queue and it has received replies from all other processes.
- After exiting the critical section, it sends a release message to all processes to remove its request from their queues.
2. Ricart-Agrawala Algorithm
- Idea: A more efficient algorithm than Lamport's, reducing the number of messages needed.
- Mechanism:
- A process sends a timestamped request message to all other processes.
- Other processes reply with a grant message if they are not interested in the critical section or if the requesting process has a higher priority (based on timestamp).
- The process can enter the critical section after receiving a reply from all processes.
- Upon exiting, it sends a release message to all processes.
3. Token Ring Algorithm
- Idea: Uses a token that circulates among processes. The process holding the token can enter the critical section.
- Mechanism:
- Processes are arranged in a logical ring.
- The token is passed around the ring. When a process receives the token, it can enter the critical section.
- After exiting the critical section, it passes the token to the next process in the ring.
- Advantage: Simplicity and fewer messages as only the token is passed.
4. Maekawa's Algorithm
- Idea: Reduces the number of messages by using a voting mechanism among a subset of processes.
- Mechanism:
- Each process is associated with a unique set of other processes (voting set).
- To enter the critical section, a process must receive permission from all processes in its voting set.
- A process grants permission if it is not in the critical section and has not granted permission to another process.
- Upon exiting, it sends a release message to its voting set.