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

## This note was uploaded on 10/11/2010 for the course COS COS226 taught by Professor Klazar during the Spring '10 term at University of Pretoria.

### Page1 / 10

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

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

View Full Document
Ask a homework question - tutors are online