# Prof. Jennifer Welch 1. FIFO Queue Example 2  Sequential specification of a FIFO queue:  operation with invocation enq(x) and response ack  operation.

## Presentation on theme: "Prof. Jennifer Welch 1. FIFO Queue Example 2  Sequential specification of a FIFO queue:  operation with invocation enq(x) and response ack  operation."— Presentation transcript:

Prof. Jennifer Welch 1

FIFO Queue Example 2  Sequential specification of a FIFO queue:  operation with invocation enq(x) and response ack  operation with invocation deq and response return(x)  a sequence of operations is allowable iff each deq returns the oldest enqueued value that has not yet been dequeued (returns  if queue is empty)  For the current discussion, assume that a given implementation of a shared FIFO queue achieves linerizability.

 The term “register” or “read/write register” is used here to refer to shared memory variables on which only read &write operations may be performed  On next slide:  Q is a shared FIFO queue  Prefer[i] is a shared read/write register 3

Consensus Algorithm for n = 2 Using FIFO Queue (i = 0, 1 for the two processes) 4 Initially Q = [0] and Prefer[i] =  Prefer[i] := p i 's input val := deq(Q) if val = 0 then decide on p i 's input else temp := Prefer[1 - i] decide temp one shared FIFO queue two shared registers write my input into my register use shared queue to arbitrate between the 2 procs: first one to dequeue the initial 0 wins, decision value is its input loser obtains decision value from other proc's register

Extend Algorithm to More Procs? 5  Can we use FIFO queues to solve consensus with more than 2 procs?  The ability to atomically dequeue a value was key to the 2-proc alg:  one proc. learns it is the winner  the other learns it is the loser, therefore the id of the winner is obvious  Not clear how to handle 3 procs.  Suppose we have a different data type:

Compare & Swap Specification 6 compare&swap(X : shared memory address, old: value, new: value) previous := X // previous is a local var. if previous = old then X := new return previous X old new

 Assume that we have an implementation of a shared compare-and-swap object that satisfies linearizability 7

Consensus Algorithm Using Compare-and- Swap 8 Initially First =  val := compare&swap(First, , my input) if val =  then decide on my input else decide val one shared C&S object simultaneously indicate whether you are the winner and the value to be decided by all the losers if First =  then replace with my input

 Achieves consensus among n processes even if any number of them crash 9

Download ppt "Prof. Jennifer Welch 1. FIFO Queue Example 2  Sequential specification of a FIFO queue:  operation with invocation enq(x) and response ack  operation."

Similar presentations