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

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

1 Mutual Exclusion with Shared Memory Slides by Prof. Jennifer Welch

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

View Full Document
2 Read/Write Shared Variables In one atomic step a processor can read the variable or write the variable but not both!
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

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

View Full Document
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
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)

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

View Full Document
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.
7 Mutual Exclusion Case 2 Is proved using arguments similar to those for Case 1.

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

## 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
Ask a homework question - tutors are online