Common2 Extended to Stacks Adam Morrison joint with Eli Gafni Yehuda Afek.

24
Common2 Extended Common2 Extended to Stacks to Stacks Adam Morrison Adam Morrison joint with joint with Eli Gafni Eli Gafni Yehuda Afek Yehuda Afek

Transcript of Common2 Extended to Stacks Adam Morrison joint with Eli Gafni Yehuda Afek.

Common2 ExtendedCommon2 Extendedto Stacksto Stacks

Adam MorrisonAdam Morrisonjoint withjoint with

Eli GafniEli GafniYehuda AfekYehuda Afek

ModelModel

• Shared memoryShared memory model. model.

• Wait-free linearizable Wait-free linearizable algorithms. algorithms.

ComputabilityComputability

ComputabilityComputability

Snapshot Snapshot implementationimplementation fromfrom read-write registersread-write registers..

StackStack??

X X implementationimplementation fromfrom stacks stacks and and read-write registersread-write registers??

Wait-free hierarchyWait-free hierarchyCo

nsen

sus

Cons

ensu

s num

ber

num

ber

11

22

[[Herlihy 91Herlihy 91]]

Object’s Object’s consensus numberconsensus number::Maximum number of Maximum number of processes that can processes that can implement consensus usingimplement consensus usingcopies of the object andcopies of the object and R/W registers.R/W registers.

Wait-free hierarchyWait-free hierarchyCo

nsen

sus

Cons

ensu

s num

ber

num

ber

11

22

Stack

Register

[[Herlihy 91Herlihy 91]]

Wait-free hierarchyWait-free hierarchyCo

nsen

sus

Cons

ensu

s num

ber

num

ber

11

22

Stack

F&A SwapQueue

Register

[[Herlihy 91Herlihy 91]]

swap(x):swap(x):

old := old := vv

vv := x := x

returnreturn old old

F&A(x):F&A(x):

old := old := vv

vv += x += x

returnreturn old old

Queue

Wait-free hierarchyWait-free hierarchyCo

nsen

sus

Cons

ensu

s num

ber

num

ber

11

22

Stack

F&A Swap

Register

[[Herlihy 91Herlihy 91]]

More than 2 processes?More than 2 processes?

Common2Common2

Queue

This talkThis talkCo

nsen

sus

Cons

ensu

s num

ber

num

ber

11

22

Stack

F&A Swap

Register

Common2Common2

Stack algorithmStack algorithm

0

rr

cellscells

ØØ

ØØ

ØØ

ØØ

ØØ

ØØ

ØØ

Pop() {Pop() { Push(x) {Push(x) {

for t:=F&A(r,0)-1for t:=F&A(r,0)-1 t := F&A(r,1) t := F&A(r,1)

downto 0 {downto 0 { cells]t[ := x cells]t[ := x

x := swap(cells]t[, Ø)x := swap(cells]t[, Ø) }}

if (x != Øif (x != Ø(( return x return x

}}

return EMPTYreturn EMPTY

{{

Stack algorithmStack algorithm

0

rr

cellscells

Push(x)Push(x)1

x

Push(y)Push(y)

2

PopPop

SwapSwap

SwapSwap

ØØ

ØØ

ØØ

ØØ

ØØ

ØØ

ØØ

Wait-free

Wait-free

Linearizability proofLinearizability proof

Linearizability proofLinearizability proof• Concurrent matching Push/Pop pairs can Concurrent matching Push/Pop pairs can

be ignored.be ignored.

Obtain an execution where Pop starts after Obtain an execution where Pop starts after corresponding Push has finished.corresponding Push has finished.

Push(x)Push(x) Push(y)Push(y) Pop: yPop: y

Push(z)Push(z)

Pop: zPop: z

Linearizability proofLinearizability proofLinearizability: Linearizability: assign each assign each

operation a linearization point at operation a linearization point at some some eventevent during its execution. during its execution.

Handling tiesHandling ties: build explicit : build explicit sequential order to breaks ties.sequential order to breaks ties.

Linearizing procedure thatLinearizing procedure thatprocesses the execution,processes the execution,using an using an auxiliary arrayauxiliary array,,and outputs aand outputs alinearization.linearization.

Proof techniqueProof technique

auxaux

Auxiliary arrayAuxiliary array

auxaux

xLin=Push(y) Pop:y Push(x)Lin=Push(y) Pop:y Push(x)

Push is linearized when it writes:Push is linearized when it writes:If to top of array, linearized now.If to top of array, linearized now.Else, with the PushElse, with the Pushabove it.above it.

Linearizing PushLinearizing Push()()

auxaux

x

zPush(z)Push(z)

Lin=Push(y) Pop:y Push(x)Lin=Push(y) Pop:y Push(x)

Push(w)Push(w) w

Lin=Push(y) Pop:yLin=Push(y) Pop:y Push(w)Push(w) Push(x)Push(x) Push(z)Push(z)

Pops are linearized as soon as their returnPops are linearized as soon as their returnvalue is at top value is at top of the auxiliary arrayof the auxiliary array..

Linearizing PopLinearizing Pop()()

cellscells

xx

zz

w

Lin=Push(y) Pop:y Push(w) Push(x) Push(z)Lin=Push(y) Pop:y Push(w) Push(x) Push(z)

Pop:xPop:x Pop:zPop:z

Pop:xPop:x

xx

zz

ww

Pop:xPop:x

auxaux

Pop:zPop:z

Pop:zPop:z

EMPTYEMPTY

Linearization proc correctnessLinearization proc correctness•Linearization is a valid stack Linearization is a valid stack

execution. execution. •Linearization respects real-time Linearization respects real-time

order.order.

Push is linearized when it writes:Push is linearized when it writes:If to top of array, linearized now.If to top of array, linearized now.Else, with the PushElse, with the Pushabove it.above it.

Linearizing PushLinearizing Push()()

auxaux

x

zPush(z)Push(z)

Push(w)Push(w) w

Push(w)Push(w)

Push(x)Push(x)

F&AF&A

F&AF&A writewrite

writewrite

Linearization proc correctnessLinearization proc correctness•Linearization is a valid stack Linearization is a valid stack

execution. execution. •Linearization respects real-time Linearization respects real-time

order.order.•Every operation is linearized.Every operation is linearized.

Pops are linearized as soon as their returnPops are linearized as soon as their returnvalue is at top of the auxiliary array.value is at top of the auxiliary array.

Every Pop() is linearizedEvery Pop() is linearized

cellscells

xx

zzPop:xPop:x

xx

zz

Pop:xPop:x

auxaux

Pop:zPop:z

ww ww

Pop:x – first to finish without being linearizedPop:x – first to finish without being linearized

Linearization proc correctnessLinearization proc correctness•Linearization is a valid stack Linearization is a valid stack

execution. execution. •Linearization respects real-time Linearization respects real-time

order.order.•Every operation is linearized.Every operation is linearized.

Queue

ConclusionConclusionCo

nsen

sus

Cons

ensu

s num

ber

num

ber

11

22

Stack

F&A Swap

Register

Common2Common2

??