Lamport's Non-Token-Based
Algorithm
Distributed Mutual Exclusion
Presented by: [Your Name]
Date/Institution/Class
Basics of Mutual Exclusion in
Distributed Systems
• • Mutual exclusion ensures only one process
accesses the critical section (CS) at a time.
• • Distributed systems lack shared memory or a
global clock.
• • Two types:
• - Token-based (uses a token)
• - Non-token-based (uses timestamps)
• • Lamport’s algorithm is non-token-based.
Introduction to Lamport’s
Algorithm
• • Proposed by Leslie Lamport in 1978.
• • Ensures mutual exclusion via message
passing and logical clocks.
• • Total ordering of events using Lamport
timestamps.
• • Uses 3 message types: REQUEST, REPLY,
RELEASE.
Logical Clocks Recap
• • Assign timestamps to events.
• • Rules:
• - Increment clock before sending.
• - On receive: Clock = max(local, received) + 1
• • Ensures 'happens-before' relation.
Lamport’s Algorithm – Steps
• 1. Requesting CS:
• - Send REQUEST(timestamp, processID) to
all.
• - Add to local request queue.
• 2. Receiving Request:
• - Add to queue, send REPLY.
• 3. Enter CS:
• - Own request at top & received all REPLYs.
• 4. Release CS:
Example with 3 Processes
• • P1, P2, P3 send REQUESTs with timestamps.
• • All send REPLYs to each other.
• • Process with earliest timestamp enters CS
first.
• • Others wait for RELEASE.
Visual Example
• • Use a sequence diagram or timeline:
• - Show REQUEST, REPLY, RELEASE flow.
• - Indicate timestamps and queue state.
Advantages
• • No starvation: FIFO order.
• • Fairness via timestamps.
• • No special coordinator or token.
• • Fully distributed operation.
Limitations
• • High message overhead: 3(N-1) per CS entry.
• • Queue maintenance required.
• • Single point of failure if a process crashes.
• • No fault tolerance without extra
mechanisms.
Time & Message Complexity
• • Message Complexity:
• - 3(N - 1) messages (REQUEST, REPLY,
RELEASE).
• • Time Complexity:
• - Entry to CS: 2 message delays.
• - Exit: 1 message delay.
Comparison with Other Algorithms
• Algorithm | Token-based | Msgs/CS |
Fairness | Fault Tolerance
• --------------- |
------------|---------|----------|----------------
• Lamport | No | 3(N-1) | Yes | No
• Ricart-Agrawala | No | 2(N-1) | Yes |
No
• Token Ring | Yes | ~1 | Yes | No
Conclusion
• • Foundational algorithm for mutual exclusion.
• • Fair, logical clock-based ordering.
• • Simple yet message-intensive.
References
• • Leslie Lamport, “Time, Clocks, and the
Ordering of Events in a Distributed System”
• • Tanenbaum, Coulouris Distributed Systems
textbooks
• • Lecture notes/articles