COS226 - Lecture - Primitive Synchronization Operations - 3

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

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

View Full Document Right Arrow Icon
COS226: Concurrent Systems Chapter 5: Primitive Synchronization Operations - Part 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
RMW Methods An exception: compareAndSet(e, u): f e,u (v) = v if v ≠ e else u
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Nontrivial RMW Methods class RMWConsensus<T> extends ConsensusProtocol<T> { // initialize to v such that // f(v) != v private RMWRegister r = new RMWRegister(v); }
Background image of page 6
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]; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online