{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

COS226 - Lecture - Mutual Exclusion - 2

# COS226 - Lecture - Mutual Exclusion - 2 - A j → CS B k...

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

COS226: Concurrent Systems Chapter 2: Mutual Exclusion Part 2

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

View Full Document
LockOne Proof Lemma 2.3.1: The LockOne algorithm satisfies mutual exclusion. Proof: Suppose not. Then there exist integers j and k such that CS A j → CS B k and CS B k CS A j . Consider each thread's last execution of the lock() method before entering its k th (j th ) critical section.
LockOne Proof write A (flag[A] = true) → read A (flag[B] == false) → CS A (2.3.1) write B (flag[B] = true) → read B (flag[A] == false) → CS B (2.3.2) read A (flag[B] == false) → write B (flag[B] = true) (2.3.3)

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

View Full Document
LockOne Proof write A (flag[A] = true) read A (flag[B] == false) write B (flag[B] = true) read B (flag[A] == false)
LockTwo Proof Lemma 2.3.2 The LockTwo algorithm satisfies mutual exclusion. Proof: Suppose not. Then there exist integers j and k such that CS

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.

Unformatted text preview: A j → CS B k and CS B k → CS A j . Consider each thread's last execution of the lock() method before entering its k th (j th ) critical section. LockTwo Proof write A (victim = A) → read A (victim == B) CS → A (2.3.5) write B (victim = B) → read B (victim == A) CS → B (2.3.6) LockTwo Proof write A (victim = A) → write B (victim = B) → read A (victim = B) (2.3.7) The Peterson Lock class Peterson implements Lock { private boolean flag = new boolean[2]; private int victim; The Peterson Lock public void lock() { int i = ThreadID.get(); int j = 1 – i; flag[i] = true; victim = i; while (flag[j] &amp;amp;&amp;amp; victim == i) {} } The Peterson Lock public void unlock() { int i = ThreadID.get(); flag[i] = false; }...
View Full 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