{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

COS226 - Lecture - Mutual Exclusion - 3

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

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

Critical Section Protected by Mutual Exclusion Implement as Lock LockOne  2-Threads LockTwo PetersonLock n-Threads Filter Lock Lamport's  Bakery

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

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

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

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

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

View Full Document
The Filter Lock public void unlock() { int me = ThreadID.get(); level[me] = 0; }
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,

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern