COS226 - Lecture - Primitive Synchronization Operations - 2

COS226 - Lecture - Primitive Synchronization Operations - 2...

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

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

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

View Full Document Right Arrow Icon
Consensus The following conditions must be met: consistency: all threads decide the same value; validity: the decision value is some thread's input. public interface Consensus<T> { T decide(T value); }
Background image of page 2
Generic Consensus Protocol public abstract class ConsensusProtocol<T> implements Consensus<T> { protected T[] proposed = (T[]) new Object[N]; void propose(T value) { proposed[ThreadID.get()] = value; } abstract public T decide(T value); }
Background image of page 3

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

View Full Document Right Arrow Icon
FIFO Queues Theorem 5.4.1 : The two-dequeuer FIFO queue class has consensus number of at least 2.
Background image of page 4
FIFO Queues public class QueueConsensus<T> extends ConsensusProtocol<T> { private static final int WIN = 0; private static final int LOSE = 1; Queue queue; }
Background image of page 5

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

View Full Document Right Arrow Icon
FIFO Queues public QueueConsensus() { queue = new Queue(); queue.enq(WIN); queue.enq(LOSE); }
Background image of page 6
FIFO Queues public T decide(T value) { propose(value); int status = queue.deq(); int i = ThreadID.get(); if (status == WIN) return proposed[i]; else return proposed[1-i]; }
Background image of page 7

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

View Full Document Right Arrow Icon
Background image of page 8
Background image of page 9

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

View Full Document Right Arrow Icon
Background image of page 10
Background image of page 11

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

View Full Document Right Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: FIFO Queues Corollary 5.4.1 : It is impossible to construct a wat-free implementation of a queue, stack priority queue, set or list from a set of atomic registers. Theorem 5.4.1 : FIFO queues have consensus number 2. FIFO Queues Proof: By contradiction. Assumptions: ● We have a consensus protocol for threads A, B and C; ● The protocol has a critical state s; ● A's next move leads to a 0-valent state; ● B's next move leads to a 1-valent state. FIFO Queues s'' s A deq 1 B deq A deq B deq s' C runs solo C runs solo FIFO Queues ● Suppose: A enq(a) and B deq() ● If the queue is non-empty, the methods commute and C cannot observe the order in which they occurred; ● If the queue is empty, the 1-valent state (B deq() and A enq(a) ) is indistinguishable from the 0-valent state (A enq(a) ). s'' s A enq(a) B enq(b) A enq(a) B enq(b) s' C runs solo 1 C runs solo run A until deq a run A until deq b run B until deq b run B until deq a...
View Full Document

{[ snackBarMessage ]}

Page1 / 12

COS226 - Lecture - Primitive Synchronization Operations - 2...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online