L12b.sp11 - Mutual Exclusion with Shared Memory Slides by...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Mutual Exclusion with Shared Memory Slides by Prof. Jennifer Welch
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Read/Write Shared Variables In one atomic step a processor can read the variable or write the variable but not both!
Background image of page 2
3 Bakery Algorithm An algorithm for no lockout mutual exclusion using 2n shared read/write variables booleans Choosing[i] : initially false, written by p i and read by others integers Number[i] : initially 0, written by p i and read by others
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Bakery Algorithm Code for entry section: Choosing[i] := true Number[i] := max{Number[0], . .., Number[n-1]} + 1 Choosing[i] := false for j := 0 to n-1 (except i) do wait until Choosing[j] = false wait until Number[j] = 0 or (Number[j],j) > (Number[i],i) endfor Code for exit section: Number[i] := 0
Background image of page 4
5 Bakery Algorithm Provides Mutual Exclusion Lemma (4.5): If p i is in the critical section and Number [ k ] ≠ 0 ( k i ), then ( Number [ k ], k ) > ( Number [ i ], i ). Proof : Consider two cases: p i in CS and Number[k] ≠ 0 p i 's most recent read of Number[k]; Case 1: returns 0 Case 2: (Number[k],k) > (Number[i],i)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Mutual Exclusion Case 1 p i in CS and Number[k] ≠ 0 p i 's most recent read of Number[k], returns 0. So p k is in remainder or choosing number. p i 's most recent read of Choosing[k], returns false. k reads Number[i] only after p i wrote Number [i] (Number[i],i)<(Num ber[k],k) p i 's most recent write to Number[i] So p k chooses number in this interval, sees p i 's number, and chooses a larger one.
Background image of page 6
7 Mutual Exclusion Case 2 Is proved using arguments similar to those for Case 1.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Mutual Exclusion for Bakery Algorithm Lemma (4.6): If p i is in the critical section, then Number [i] > 0. Proof is a straightforward induction.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

L12b.sp11 - Mutual Exclusion with Shared Memory Slides by...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online