Hwajung Lee ITEC 452 Distributed Computing Lecture 7
Hwajung Lee ITEC 452 Distributed Computing Lecture 7 Mutual Exclusion
Mutual Exclusion p 0 CS p 1 CS p 2 CS p 3 CS
Why mutual exclusion? Some applications are: Resource sharing q q Avoiding concurrent update on shared data Medium Access Control in Ethernet Collision avoidance in wireless broadcasts
Specifications ME 1. [Mutual Exclusion] At most one process in the CS. (Safety property) ME 2. [Freedom from Deadlock] No deadlock. (Safety property) ME 3. [Progress] Every process trying to enter its CS must eventually succeed. (Liveness property) Violation of ME 3 is livelock (=starvation) Progress is quantified by the criterion of bounded waiting. It measures a form of fairness by answering the question: Between two consecutive CS trips by one process, how many times other processes can enter the CS? There are many solutions, both on the shared memory model and the message-passing model
Message passing solution: Centralized decision making server busy: boolean queue req reply release Client do true send request; reply received enter CS; send release; <other work> od Server clients do request received and not busy send reply; bus request received and busy enqueue sender release received and queue is empty busy: = fal release received and queue not empty send rep to the head of the queue od
Comments q Centralized solution is simple. q But the server is a single point of failure. This is BAD. q ME 1 -ME 3 is satisfied, but FIFO fairness is not guaranteed. Why? Can we do better? Yes!
Decentralized solution 1 {Lamport’s algorithm} 1. To request entry into its CS, broadcast a timestamped request to all. 2. At each process i: Request received enqueue it in local Q. If process i is not in CS send ack, else postpone sending ack until it exit from CS. 3. Enter CS, when (i) You are at the head of your Q (ii) You have received ack from all 4. To exit from the CS, (i) Delete the request from your Q, and (ii) Broadcast a timestamped release 5. When a process receives a release message, it removes the sender from its Q. Completely connected topolog
Analysis of Lamport’s algorithm Can you show that it satisfies all the properties (i. e. ME 1, ME 2, ME 3) of a correct solution? Observation. Processes making a decision to enter CS must have identical views of their local queues, when all acks have been received. Proof of ME 1. At most one process can be in its CS at any time. Proof by contradiction Suppose not, and both j, k enter their CS. This implies j in CS Q. ts. j < Q. ts. k k in CS Q. ts. k < Q. ts. j Impossible.
Analysis of Lamport’s algorithm Proof of ME 2. (No deadlock) and ME 3. (progress) Basis. When process i makes a request, there may be at most n -1 processes ahead of process i in its request queue. Inductive step. Assume K (1<= K <= n-1) processes ahead of process i in the request queue. (1) # of process ahead (2) bounded number of steps to enter CS
- Slides: 9