COS226 - Lecture - Mutual Exclusion - 3

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

This preview shows pages 1–7. 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 (( 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; }
This is the end of the preview. Sign up to access the rest of the 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 / 12

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

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

View Full Document
Ask a homework question - tutors are online