1 / 24

Chapter 10 Mutual Exclusion

Chapter 10 Mutual Exclusion. Presented by Yisong Jiang. Mutual Exclusion Using Read-Modify-Write Shared Variables.

bianca
Télécharger la présentation

Chapter 10 Mutual Exclusion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 10 Mutual Exclusion Presented by Yisong Jiang

  2. Mutual Exclusion Using Read-Modify-Write Shared Variables • In this section , we consider mutual exclusion using read-modify-write shared memory. That is, a process is able, in one instantaneous step, to access a shared variable and to use the variable value and the process state to determine a new variable value and a new process state.

  3. Mutual Exclusion Using Read-Modify-Write Shared Variables • The basic problem TrivialME: In this algorithm , the shared variable x has value 1 exactly if the resource has been granted to some process. Any process in the trying region simply tests x until it discovers x =0, at which time it immediately sets x:=1. Upon exiting, a process resets x:=0 See Page 310 for the TrivialME algorithm

  4. Mutual Exclusion Using Read-Modify-Write Shared Variables • Bounded Bypass The TrivialME algorithm does not guarantee any high-level-fairness conditions. However, we can obtain very strong high-level-fairness conditions, even a FIFO condition, still just using a single shared variable.

  5. Mutual Exclusion Using Read-Modify-Write Shared Variables • QueueME algorithm: The processes maintain a queue of process indices, initially empty, in the shared variable. A process that enters T adds its index to eht end of the queue; a process that finds itsself at the beginning of the queue goes to C; and when a process leaves C, it deletes itself from the queue. See Page 311 for the QueueME algorithm

  6. Mutual Exclusion Using Read-Modify-Write Shared Variables • QueueME guarantees well-formedness, mutual exclusion, and progress. Moreover, it satisfies the high-level-fairness condition that entry to the critical region is FIFO with respect to the first locally controlled action in the trying region. This implies that QueueME guarantees bounded bypass( with a bound of 1) • Theorem 10.39 QueueME solves the mutual exclusion problem and guarantees bounded bypass

  7. Mutual Exclusion Using Read-Modify-Write Shared Variables • For the QueueME , the shared variable requires Ω(nlogn) bits. It is not very hard to achieve the same type of FIFO behavior as the QueueME algorithm, using a shared variable with only n2 values(2logn bits). • TicketME algorithm ( see page 313)

  8. Mutual Exclusion Using Read-Modify-Write Shared Variables

  9. Mutual Exclusion Using Read-Modify-Write Shared Variables • Theorem 10.40 TicketME solves the mutual exclusion problem and guarantees bounded bypass, using n2 values of shared memory. • A simulation proof • We relate the TicketME algorithm to a new Infinite TicketME algorithm that is just like TicketME except that it uses an infinite sequence of tickets rather than counting modulo n. Then TicketME can be seen as a reduced-complexity version of Infinite TicketME(page 322).

  10. Mutual Exclusion Using Read-Modify-Write Shared Variables

  11. Mutual Exclusion Using Read-Modify-Write Shared Variables

  12. Mutual Exclusion Using Read-Modify-Write Shared Variables

  13. Mutual Exclusion Using Read-Modify-Write Shared Variables • Lemma 10.46 f is a simulation relation from T to I Proof: • For the first condition, a start state s of T consists of th unique start state of the TicketME algorithm and arbitrary start states for the users. It is easy to see that the unique start state of the Infinite TicketMe algorithm, together with the same start states for the users, is in f(s) • The second condition is proved by a case analysis, according to the type of action being performed

  14. Mutual Exclusion Using Read-Modify-Write Shared Variables • Proof Sketch of Theorem 10.40 • Lemma 10.46 and Theorem 8.12 imply that traces(T) Є traces(I). So the fact that these 3 conditions hold for I implies that they also hold for T. This implies that TicketME guarantees the well-formednes, mutual exclusion, and FIFO conditions. • To prove the progress condition, we argue fairtraces(T) Є fairtraces(I). Let b Є fairtraces(T) and let a be any fair execution of T such that b=trace(a). Then by theorem 8.13, there is a corresponding execution a’ of I satisgying the two conditions enumerated above. In particular, the traces of a and a’ are the same, so that b=trace(a’). We claim a’ is a fair execution of I.

  15. Mutual Exclusion Using Read-Modify-Write Shared Variables • It follows that a’ is a fair execution of I, which implies that b Є fairtraces(I). Thus fairtraces(T) Є fairtraces(I). Since the progress condition can be expressed as a property of fair traces, this implies that the progress condition carries over from Infinite TicketME to TicketME.

  16. Mutual Exclusion Using Read-Modify-Write Shared Variables • Theorem 10.41 Let A be an n-process mutual exclusion algorithm guaranteeing bounded bypass, using a single read-modify-write variable. Then the number of distinct values the variable can take on is at least n

  17. Mutual Exclusion Using Read-Modify-Write Shared Variables • Proof • Suppose A is an n-process mutual exclusion algorithm guaranteeing bounded bypass, with a bypass bound of a. We proceed by contradiction: we construct an execution in which some process is bypassed more than a times • We start by defining a sequence of finite executions, α1, α2,……, αn, each an extension of the previous one. Execution α1 is obtained by letting process 1 run alone from an initial system state until it enters C.

  18. Mutual Exclusion Using Read-Modify-Write Shared Variables • To obtain α2, we extend α1 by letting process 2 enter the trying region and take one locally controlled step. Process 2 must remain in its trying region after α2, in order to avoid the mutual exclusion condition. Each process I, 3<=i<=n, also remains in its trying region. • Define si to be the system state and vi the value of the shared variable after αi, 1<=i<=n. We claim that vi ≠ vj for 1<=I, j<=n, i ≠ j, which implies the result.

  19. Mutual Exclusion Using Read-Modify-Write Shared Variables

  20. Mutual Exclusion Using Read-Modify-Write Shared Variables • Assume the contrary, that vi = vj for some particular I and j, I ≠ j, and assume i<j. then si and sj are indistinguishable to process k for every process k, k<=1<=I • Now , there is some low-level-fair execution that extends αi, involving only processes 1,…, I, that causes some process to enter C infinitely many times. The same steps can be applied after αj, again yielding an execution in which the same process enters C infinitely many times. Just running a sufficiently large portion of this execution is enough to cause process j to by bypassed more than a times by some other process, which is a contradiction.

  21. Mutual Exclusion Using Read-Modify-Write Shared Variables • A counterexample algorithm that only requires O(n) values. • BufferMainME algorithm: • Basic Idea: The trying region is divided into two pieces, called the buffer region and the main region. When processes enter the trying region, they go in to the buffer; no order information is maintained among the processes in the buffer. At some time, when the main region is empty, all processes in the buffer go to the main region, thereby emptying the buffer. From the main region, processes go one at a time, in arbitrary order, to the critical region.

  22. Mutual Exclusion Using Read-Modify-Write Shared Variables • Theorem 10.42 The BufferMainME algorithm solves the mutual exclusion problem, guaranteeing bounded bypass, using a single read-modify-write shared variable with only n+k values( for some small constant k)

  23. Mutual Exclusion Using Read-Modify-Write Shared Variables • Lockout-Freedom • The lower bound of Theorem 10.41 only holds when the high-level-fairness requirement is bounded bypass. It does not hold for lock-out freedom. We have another counterexample: Executive algorithm. • Executive algorithm: (see page 319) The idea is as follows: As in the BufferMainME, each incoming process increments a count in the shared variable, but this time the count is only allowed to take on Values 0,…n/2 before wrapping back around to 0. The count is absorbed by a supervisor, as before.

  24. Mutual Exclusion Using Read-Modify-Write Shared Variables • Theorem 10.43 The Executive algorithm solves the mutual exclusion problem, guaranteeing lockout-freedom, using a single read-modify-write shared variable with only n/2+k values.

More Related