COS226 - Lecture - Mutual Exclusion - 3

COS226 - Lecture - Mutual Exclusion - 3 - CriticalSection

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

View Full Document Right Arrow Icon
    Critical Section Protected by Mutual Exclusion Implement as Lock LockOne  2-Threads LockTwo PetersonLock n-Threads Filter Lock Lamport's  Bakery
Background image of page 1

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

View Full DocumentRight Arrow Icon
    The Filter Lock CS . . . 2 threads n-2 threads n-1 threads non-CS; n threads l = 0 l = 1 l = 2 l = n-2 l = n-1
Background image of page 2
    The Filter Lock Levels satisfy two properties: At least one thread trying to enter level l, succeeds; If more than one thread is trying to enter level l,  then at least one is blocked.
Background image of page 3

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

View Full DocumentRight Arrow Icon
    The Filter Lock class Filter implements Lock { int [] level; int [] victim; public Filter(int n) { level = new int[n]; victim = new int[n]; for (int i = 0; i < n; i++) level[i] = 0; } }
Background image of page 4
    The Filter Lock public void lock() { int me = ThreadID.get(); for (int i = 1; i < n; i++) { level[me] = i; victim[i] = me; while (( victim[i] == me)) {} } }
Background image of page 5

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

View Full DocumentRight Arrow Icon
    The Filter Lock public void unlock() { int me = ThreadID.get(); level[me] = 0; }
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

COS226 - Lecture - Mutual Exclusion - 3 - CriticalSection

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

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