{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

COS226 - Lecture - Mutual Exclusion - 3

COS226 - Lecture - Mutual Exclusion - 3 - CriticalSection...

Info icon This preview shows pages 1–12. 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
Image of page 1

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

View Full Document Right 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
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.
Image of page 3

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

View Full Document Right 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; } }
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 (( k != me)(level[k] >= i && victim[i] == me)) {} } }
Image of page 5

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

View Full Document Right Arrow Icon
    The Filter Lock public void unlock() { int me = ThreadID.get(); level[me] = 0; }
Image of page 6
    The Filter Lock Peterson Lock: flag[A] = true; victim = A; while (flag[B] && victim == A) {} Filter Lock: level[A] = i; victim[i] = A; while there is a thread in the next level,
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern