100 likes | 218 Views
Revisiting Logical Clocks: Mutual Exclusion. Problem statement: Given a set of n processes, and a shared resource, it is required that: Mutual exclusion At any time, at most one process is accessing the resource Liveness
E N D
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: • Mutual exclusion • At any time, at most one process is accessing the resource • Liveness • If a process requests for the resource, it can eventually access the resource
Solution to mutual exclusion • How could we do this if all processes shared a common clock • Each process timestamps its request • The process with lowest timestamp is allowed to access critical section • What are the properties of clocks that enable us to solve this problem? • Is there another type of clock that could help is to solve this problem
Solution to mutual exclusion, based on logical clocks • Messages are timestamped with logical clocks • Each process maintains a queue of pending requests • When process j wants to access the resource, it adds its timestamp to the queue, and sends a request message containing its timestamp to all other processes • When process k receives a request message from j, it sends a reply message to j
Solution to mutual exclusion, based on logical clocks (continued) • Process j accesses the resource (enters critical section) iff • it has received a reply from every other process • its queue does not contain a timestamp that is smaller than its own request • After a process is done accessing its critical section, it sends a release message to all processes and removes its own request from the pending queue • When a process k receives the release message from j,it removes the entry of j from its pending queue
Solution to mutual exclusion, based on logical clocks (continued) • This is called Lamport’s mutual exclusion algorithm • What is the number of messages sent for every access to critical section?
Optimizations • Should a process wait for a reply message from every other process? • Should a process send a reply message immediately? • Answer these questions to obtain a protocol where only 2 (n-1) messages are used for each critical section
Classification of Mutual Exclusion Algorithms • Quorum Based • Each node is associated with a quorum Qj • When j wants to enter critical section, it asks for permission from all nodes in this quorum • What property should be met by the quorums of different processes? • Token Based • A token is circulated among nodes; the node that has the token can access critical section • We will look at these later
Which category would Lamport’s protocol fit in? • What is the quorum of a process in this algorithm? • What are the possibilities of different quorums
Taking Quorum Based Algorithms to Extreme • Centralized mutual exclusion • A single process `coordinator' is responsible for ensuring • mutual exclusion. • Each process requests the coordinator whenever it wishes to access the resource. • The coordinator permits only one process to access the resource at a time. • After a process accesses the resource, it sends a reply to the coordinator. • Quorum for all processes is {c} where c is the coordinator
Centralized mutual exclusion • Problem : What if the coordinator fails? • Solution : Elect a new one