Common2 extended to stacks and unbound concurrency By:Yehuda Afek Eli Gafni Adam Morrison May 2007...

Post on 14-Dec-2015

225 views 2 download

Transcript of Common2 extended to stacks and unbound concurrency By:Yehuda Afek Eli Gafni Adam Morrison May 2007...

Common2 extended to Common2 extended to stacks and unbound stacks and unbound

concurrencyconcurrency

By: Yehuda AfekEli GafniAdam Morrison

May 2007

Presentor: Dima Liahovitsky

1

Outline:

Introduction, refresh and definitions Wait-free stack implementation Snapshot objects Unbounded concurrency objects Summary

2

Refresh: TASRefresh: TAS

TAS object: boolean variable state, initally

TRUE

Test-and-set()v := state;state := false;return v;

3

Refresh: F&ARefresh: F&AF&A object:

int variable num, initialised at the begining

Fetch-and-add(x)v := num;num := v + x;return v;

4

Refresh: wait-freedomRefresh: wait-freedom

Definition:an algorithm is wait-free if a process invoking it will finish after a finite number of steps.

5

Refresh: linearization, Refresh: linearization, concurrencyconcurrency

Let H be a history of execution of the system: a sequence of invocation and response events.

H is linearizable if H is equivalent to some valid sequential history S, meaning that the partial order of operations in H is a sub-set of the partial order of operations in S.

Such a S is the linearization of H.

If two operations o1, o2 are incompatible by the partial order on operations induced by a history H, we say: o1 and o2 are concurrent.

6

Refresh: linearization Refresh: linearization (cntd.)(cntd.)

Example: Stack

7

St:St.push(a)

St.push(b) St.pop(b)

St.pop(a)

time

St.pop(x) St.pop(y)St.push(y)St.push(x)

not

linearizable

linearizable

Concurrent operations Linearization

points

Refresh: consensusRefresh: consensusConsensus object: Operation: decide(xi), returns a value Supports:

Agreement: all processes calling for decide() get the same return value

Validity: the value returned to processes from decide() must be an input of one of them

8© 2003 Herlihy and Shavit 13

The Consensus object: each process has a private input

32 1921

© 2003 Herlihy and Shavit 15

They Agree on Some Process’ I nput

1919 19

Refresh: consensus Refresh: consensus (cntd.)(cntd.)

Consensus power of object obj:The largest number of processes that can wait-

free reach consensus using copies of obj object, and registers.

Consensus power k k-consensus

Consensus hierarchy:K-consensus object cannot implement (k+1)-

consensus object

9

Common2Common2

Definition (by Y. Afek, 1993):Family of objects that are wait-free implementable from 2-consensus objects for any number of processes.

It has been known that F&A, TAS are inside Common2.

It has been believed that not FIFO queue nor LIFO stack are inside Common2.

Hmmmmmm… maybe stack IS inside Common2?..

10

Outline:

Introduction, refresh and definitions Wait-free stack implementation Snapshot objects Unbounded concurrency objects Summary

11

Wait-free STACKWait-free STACK

12

Push(x) {1. i = F&A(range, 1);2. items[i] = x;}

Shared Items:range: F&A object initialized to 1 //index for the next pushitems: array [1…] of registers //items[0] = $T: array [1…] of TAS object

Pop() {1. t = F&A(range, 0) - 1;2. for i = t downto 13. X = items[i];4. If x != null then {5. If TAS(T[i]) then return x;

} // end if } // end for6. return $; //indicator of empty

stack} // end Pop

Wait-free STACKWait-free STACK

13

Let’s have a look at our implementation…

Wait-free?

Implemented from registers and 2-consensus objects?

It’s also known that TAS and F&A have n-bounded implementations from 2-consensus objects

Therefore if we show that our stack is linearizable, then we can proudly say that:

The Stack object has an n-bounded wait-free implementation from registers and 2-consensus objects=> our Stack is in Common2, by definition.

yesyes!!

yesyes!!

Wait-free STACKWait-free STACK

14

1. Eliminating concurrent Push(x)/Pop(x) from the History

time

St.push(x)

St.pop(x)

Just delete concurrent push(x)/pop(x) ?...

Dummy-push(x) { //like previus Push(x), but without array modificationi := F&A(range, 1);

}

Linearization proof sketch:

15

2. Linearizing the rest of the history (without concurrent push(x) / pop(x)):

Variables for linearization algorithm:I : array of values, initially I[0] = $ and all other cells are NULLS: history, initially empty

Terms for the linearizing algorithm L:top(I) : value in the highest index non-NULL cell of I

Linearization proof sketch:

High level eventPrimitive event

Push(x) invocationF&A(range, 1)

Push(x) responseItems[i] := x

Pop(x) invocationF&A(range, 0)

Pop(x) responseWinning TAS at T[x]

Pop($) responseLosing TAS at T[1]

Pop($) responseReading NULL from items[1]

16

2. Linearizing the rest of the history (without concurrent push(x) / pop(x)):

L(History = <e1,…,eh>) {1. for j := 1 to h do {2. if ej = <items[i] := x> { // push() response3. I[i] := x4. let y be the lowest non-NULL item stored above x in I5. if no such y exists then S := S o Push(x)6. else {7. let S = S1 o Push(y) o S2

8. S := S1 o Push(x) Push(y) o S2

9. } //end else10. } //end if11. while Pop(top(I)) is active in e1…ej {12. let v = top(I)13. S := S o Pop(v)14. If v != $ then I[index(v)] := NULL15. } //end while16. } //end for} //end L

Linearization proof sketch:

Midway Conclusions:

So what have we proved for now?

There is an n-bounded wait-free stack implementation from registers and 2-consensus objects (TAS, F&A) .

Therefore stack is in Common2.

What next?

If we show unbounded concurrency TAS and F&A implementations from registers and 2-consensus objects…Then we will automatically get an unbounded concurrency wait-free stack implementation from registers and 2-consensus objects.

17

Outline:

Introduction, refresh and definitions Wait-free stack implementation Snapshot objects Unbounded concurrency objects Summary

18

Snapshot objectSnapshot objectEach object has a “segment” = SWMR register.A process may obtain an “atomic snapshot” of all segments of

other processes.

Supports two operations:

1. update(v) : a process updates its segment to v

2. Scan(): returns an n-element vector called “view” (or V[]), with a value of each segment of all n processes

V[i] must return the value of the latest update() of process i.

scan() returns a “snapshot” of the segments array that existed at some point during the execution.

19

Snapshot exampleSnapshot example V[i] must return the value of the latest update() of process i.

scan() returns a “snapshot” of the segments array that existed at some point during the execution.

3 processes: P1, P2, P3

20

time P1.seg P2.segP3.seg

quantums1 0 0

02 1 0

03 2 0

04 2 1

05 2 1

3

Scan() starts here

Scan() ends here

one Possible snapshot returned from scan(): <2,1,0>

Not possible snapshots returned from scan(): <0,0,0> <1,1,0>

Atomic write-and-snapshotAtomic write-and-snapshotWe introduce one-shot n-bounded write-and-snapshot()

implementation.The implementation can be easily turned into long-lived one by

having each process P simulate a sequence P1, P2, ... of different processes in the one-shot implementation, where Pi performs the i-th operation of P.

Write-and-snapshot(inputi) makes update() and scan() in one procedure.

When process i calls write-and-snapshot(), it first updates its segment, and then returns a set of segments of all other processes that have already updated their segments.

Therefore if process i is the first process to complete write-and-snapshot(), it’ll receive an empty set from write-and-snapshot().

21

Atomic write-and-snapshotAtomic write-and-snapshotShared variables:

T[1..n] : array of TAS objectslevel[1..n] : array of swmr registers; initialized to n+1value[1..n] : array of swmr registers

Local variable:S : set of at most n integers; t : stores returned value of result of TAS

Write-and-snapshot(inputi) {1. value[i] := inputi;2. while(TRUE) do {3. level[i] := level[i] – 1;4. S := { j | level[j] <= level[i] }5. If |S| >= level[i] then {6. t := TAS(T[level[i]]);7. If t=TRUE then // if we won TAS8. return { value[j] | j of S };

} //if } //while

} // write-and-snapshot

22

Simpler to understan

dn-bounded implementation

There existsunbounded concurrency

wait-freeimplementation

Issues for unbounded Issues for unbounded concurrency write-and-concurrency write-and-

snapshotsnapshot1. How does a process determine in which level to start its

descent?2. How does a process decide when to stop at some level

and return from there?3. How does a process that decides to stop at level L find

out which processes are active in the levels below it, in order to return them as its immediate snapshot?

23

There exists an algorithm that solves these issues, and therefore implements unbounded concurrency write-and-snapshot().

We are going to use this unbounded concurrency write-and-snapshot() to implement unbounded concurrency F&A…

Outline:

Introduction, refresh and definitions Wait-free stack implementation Snapshot objects Unbounded concurrency objects Summary

24

Unbounded concurrency Unbounded concurrency F&AF&A

Shared variables:WS : write-and-snapshot objectargs: array[1,…] of registers, initially empty

Fetch-and-add(kp){ //invoked by process P1. args[P] := kp;2. S := WS.write-and-snapshot(); //unbounded concurrency

WAS3. return ∑Q∈S,Q!=P (args[Q]) ;} //end of F&A

25

A process P announces its input. (line 1)P then obtains an atomic write-and-snapshot Sp (line 2), and returns the sum of all inputs announced in Sp (line 3).

Unbounded concurrency Unbounded concurrency TASTAS

There is an easy implementation of TAS from F&A,

Therefore…

26

Unbounded concurrency Unbounded concurrency STACKSTACK

Push(x) {1. i = F&A(range, 1);2. items[i] = x;}

27

Shared Items:range: F&A object initialized to 1 //index for the next pushitems: array [1…] of registers //items[0] = $T: array [1…] of TAS object

Pop() {1. t = F&A(range, 0) - 1;2. for i = t downto 13. X = items[i];4. If x != null then {5. If TAS(T[i]) then return x;

} // end if } // end for6. return $; //indicator of empty

stack} // end Pop

Stack has an unbounded concurrency wait-free implementation from registers and 2-consensus objects

Outline:

Introduction, refresh and definitions Wait-free stack implementation Snapshot objects Unbounded concurrency objects Summary

28

SummarySummary

We showed a wait-free stack implementation in n-bounded concurrency model, meaning that stack object is inside Common2, refuting the previous conjecture that such an implementation is impossible.

We introduced an unbounded concurrency write-and-snapshot object, using which we easily got unbounded concurrency F&A object, using which we’ve also got unbounded concurrency TAS object.

Back to our stack, the last discovery immediately makes our stack implementation an unbounded concurrency wait-free implementation from registers and 2-consensus objects.

29

SummarySummary

• Common2 membership problem (whether every consensus power 2 object can be wait-free implemented from 2-consensus) remains open.

• The previous conjecture that a FIFO queue object cannot be implemented wait-free from Common2 objects, is not proven yet.

• Is there a natural object that is wait-free implementable from 2-consensus in the n-bounded concurrency model, but is not implementable for unbounded concurrency model?

• Our conjecture is that swap object is one such an object.

30

Open problems:

31

Thank Thank youyou!!