Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.

Similar presentations


Presentation on theme: "Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the."— Presentation transcript:

1 Hwajung Lee

2 Mutual Exclusion CS p0 p1 p2 p3

3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the grain of atomicity  Medium Access Control in Ethernet  Collision avoidance in wireless broadcasts

4 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Medium Access Control in Ethernet  Collision avoidance in wireless broadcasts

5 ME1. [Mutual Exclusion] At most one process in the CS.(Safety property) ME2. [Freedom from Deadlock] No deadlock. (Safety property) ME3. [Progress] Every process trying to enter its CS must eventually succeed. (Liveness property) Violation of ME3 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

6 clients Client do true  send request; reply received  enter CS; send release; od Server do request received and not busy  send reply; busy:= true request received and busy  enqueue sender release received and queue is empty  busy:= false release received and queue not empty  send reply to the head of the queue od busy: boolean server queue req reply release

7  Centralized solution is simple.  But the server is a single point of failure. This is BAD.  ME1-ME3 is satisfied, but FIFO fairness is not guaranteed. Why? Can we do better? Yes!

8 {Lamport’s algorithm} 1. To request entry into its CS, b roadcast 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 topology

9 Can you show that it satisfies all the properties (i.e. ME1, ME2, ME3) 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 ME1. 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  Qj.ts.j < Qk.ts.k  k in CS  Qk.ts.k < Qj.ts.j Impossible.

10 Can you show that it satisfies all the properties (i.e. ME1, ME2, ME3) 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 ME1. 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.

11 Proof of ME2. (No deadlock) The waiting chain is acyclic. i waits for j  i is behind j in all queues (or j is in its CS)  j does not wait for i Proof of ME3. (progress) New requests join the end of the queues, so new requests do not pass the old ones

12 Proof of ME2. (No deadlock) and ME3. (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

13 Proof of FIFO fairness. Proof by contradiction timestamp (j) < timestamp (k)  j enters its CS before k does so Suppose not. So, k enters its CS before j, which means k did not receive j’s request but received the ack from j for its own req. This is impossible if the channels are FIFO Message complexity of each process in one round trip to CS = 3(N-1) (N-1 requests + N-1 ack + N-1 release) k j Req (20 ) ack Req (30)


Download ppt "Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the."

Similar presentations


Ads by Google