COS226 - Lecture - Primitive Synchronization Operations - 3

# COS226 - Lecture - Primitive Synchronization Operations - 3...

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

COS226: Concurrent Systems Chapter 5: Primitive Synchronization Operations - Part 3

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

View Full Document
Read-Modify-Write Operations Let F be a set of functions from integers to integers; A method is RMW for F if it atomically replaces register value v with f(v) for some f F , and returns v.
RMW Methods From java.util.concurrent: getAndSet(x): f x (v) = x getAndIncrement(): f(v) = v + 1 getAndAdd(k): f k (v) = v + k get(): f(v) = v

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

View Full Document
RMW Methods An exception: compareAndSet(e, u): f e,u (v) = v if v ≠ e else u
Nontrivial RMW Methods Theorem 5.6.1: Any nontrivial RMW register has a consensus number of at least 2. Proof: Fig. 5.14. Since there exists a function that is not the identity function, there exists a value v such that f(v) v.

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

View Full Document
Nontrivial RMW Methods class RMWConsensus<T> extends ConsensusProtocol<T> { // initialize to v such that // f(v) != v private RMWRegister r = new RMWRegister(v); }
Nontrivial RMW Methods public T decide(T value) { propose(value); int i = ThreadID.get(); int j = 1-i; if (r.rmw() == v) return proposed[i]; else return proposed[j]; }

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 ]}

### Page1 / 16

COS226 - Lecture - Primitive Synchronization Operations - 3...

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

View Full Document
Ask a homework question - tutors are online