110
Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica midlab laboratory

Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

Embed Size (px)

Citation preview

Page 1: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

Computing with Concurrent Objects

speaker

sara tucci piergiovanniinstitution

università di roma “la sapienza”dipartimento di informatica e sistemistica

midlab laboratory

Page 2: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Concurrent Objects Definitionس

”The “outside” view-pointسLinearizability: what makes a concurrent object a “meaningful” programming

abstraction

The “inside” view-pointسWait-free implementation: what makes a concurrent object a “possible” programming

abstraction

A “global” look to the universe of concurrent objectsسObject hierarchy: what makes happy a “would-be theoretician” like me

Outline

Page 3: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

Lecture1: the “outside” view-point

speaker

sara tucci piergiovanniinstitution

università di roma “la sapienza”dipartimento di informatica e sistemistica

midlab laboratory

Page 4: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

What is an object? .An object in languages such as Java and C++ is a container for dataس

أ Each object provides a set of methods that are the only way to manipulate that object’s state.

أ Each object has a class which describes how its methods behave

Object descriptionسأ The application programmer interface (API)

ر pre-condition (describing the object’s state before invoking the method) ر post-condition, describing the object’s state and return value after the method returns.

أ For example, if the FIFO queue object is non-empty (pre-condition), then the deq() method will remove and return the first element (post-condition), and otherwise it will throw an exception (another pre- and post-condition).

Page 5: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Pre and Post Conditions Defining objects in terms of pre-conditions and post-conditions makes perfect sense inس

a sequential model computation where a single thread manipulates a collection of objects.

س In this case methods are called once at a time, each method invocation is followed by the corresponding return and a sequence of method calls can be defined

enq(a;ok)

method invocation

method response

enq(b;ok) deq( ;a) deq( ;b) deq()

time

exception

p

Page 6: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Concurrent Modelس If an object’s methods can be invoked by concurrent threads, then the method

executions can overlap in time, and it no longer makes sense to talk about the order of method calls.

What does it mean, in a multithreaded program, if a and b are enqueued on a FIFOسqueue during overlapping intervals? Which will be dequeued first?

enq(a;ok) deq( ;?)

at the end of the invocation, the queue surely contains a, but

during the invocation what did it happen? God knows

p

q

a a a a a aa

enq(b;ok) deq( ;?)

enq(a;ok)

where is the trick?

method call

queue’s state

Page 7: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

The Linearizability Manifesto.The Linearizability Manifestoس

Each method call should appear to “take effect” instantaneously at some moment between its invocation and response.

p

q

enq(a;ok)

enq(b;ok)

deq( ;b)

deq( ;a)

S time

aba b

Page 8: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Linearizability: scenario?Again, is this execution linearizableس

...try to put a point for each method call...

enq(a;ok) enq(b;ok)p

q deq( ;c)

enq(c;ok)r

deq( ;a)

deq( ;b)

S

aba

c ccba a

Page 9: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Linearizability: scenario?Again, is this execution linearizableس

...try to put a point for each method call...

enq(b;ok) enq(c;ok)p

q deq( ;a)

r

Sb

cb

deq( ;b)

acb

enq(a;ok)

deq( ;c)

no way...

Page 10: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing Linearizability Until now we had fun by putting points here and there...now the play is gettingس

harder...we should formalize what putting points would mean

-------------------------------- Definitions and Basic Notation ---------------------------------------- An execution of a concurrent system is modeled by a history H, which is a finiteس

sequence of method invocation and response events.

<A method invocation event is denoted as < inv (op(args), X) pس<A method response event is denoted as < res (op(res), X) pس

where op is the name of the method, args is a list of input arguments, res is a list of results (ok for void) , X is the name of the object, p the name of the process.

--------------------------------------------------------------------------------------------------------------------

enq(a;ok)p

tH: inv (enq(a), X) p res (enq(ok), X) p

Page 11: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing LinearizabilityConcurrent execution example and related Historyس

p

q

enq(a;ok)

enq(b;ok)

deq( ;a)

deq( ;b)

H: inv(enq(a),X)p, res(enq(ok)X)p, inv(enq(b)X)q, res(enq(ok)X)q,

inv(deq()X)p, res(deq(a)X)p, inv(deq()X)q, res (deq(b)X)q

Page 12: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing LinearizabilityConcurrent execution example and related Historyس

p

q

enq(a;ok)

enq(b;ok)

deq( ;a)

deq( ;b)

H: inv(enq(a),X)p, inv(enq(b)X)q, res(enq(ok)X)p,

res(enq(ok)X)q, inv(deq()X)p, inv(deq()X)q, res(deq(a)X)p

res (deq(b)X)q

Page 13: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing Linearizability

-------------------------------------------- Definitions ---------------------------------------------

A response matches an invocation if their objects names agree and their processسnames agree.

.An invocation is pending in a history if no matching response follows the invocationس

س If H is a history, complete(H) is the maximal subsequence of H consisting only of invocations and matching responses.

-----------------------------------------------------------------------------------------------------------------------

Page 14: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing LinearizabilityConcurrent execution example and related Historyس

p

q

enq(a;ok)

enq(b;ok)

deq( ;

deq( ;)

H: inv(enq(a),X)p, inv(enq(b)X)q, res(enq(ok)X)p, res(enq(ok)X)q,

inv(deq()X)p, inv(deq()X)q

complete(H): inv(enq(a),X)p, inv(enq(b)X)q, res(enq(ok)X)p, res(enq(ok)X)q

Page 15: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing Linearizability----------------------------------------- Definitions

----------------------------------------- A history H is sequential ifس

أ (1) The first event of H is an invocation.أ (2) Each invocation, except possibly the last, is immediately followed by a

matching response. A history that is not sequential is concurrent.

A process subhistory, H|p (H at p), of a history H is the subsequence of all events in Hسwhose process names are p. (An object subhistory H|X is similarly defined for an object X.)

.Two histories H and H’ are equivalent if for every process p, H|p = H’|pس

A history H is well-formed if each process subhistory H|p of H is sequential (in theسfollowing we will assume well-formed subhistories)

-----------------------------------------------------------------------------------------------------------------------------------------------------

Page 16: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing LinearizabilitySequential History Hس

p

q

enq(a;ok)

enq(b;ok)

deq( ;a)

deq( ;b)

H: inv(enq(a),X)p, res(enq(ok)X)p, inv(enq(b)X)q, res(enq(ok)X)q, inv(deq()X)p, res(deq(a)X)p, inv(deq()X)q, res (deq(b)X)q

H|p: inv(enq(a),X)p, res(enq(ok)X)p, inv(deq()X)p, res(deq(a)X)p

H|q: inv(enq(b)X)q, res(enq(ok)X)q, inv(deq()X)q, res (deq(b)X)q

well-formed subhistories

Page 17: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing Linearizability’Concurrent History Hس

p

q

enq(a;ok)

enq(b;ok)

deq( ;a)

deq( ;b)

H’: inv(enq(a),X)p, inv(enq(b)X)q, res(enq(ok)X)p, res(enq(ok)X)q, inv(deq()X)p, inv(deq()X)q, res(deq(a)X)p, res (deq(b)X)q

H’|p: inv(enq(a),X)p, res(enq(ok)X)p, inv(deq()X)p, res(deq(a)X)p

H’|q: inv(enq(b)X)q, res(enq(ok)X)q, inv(deq()X)q, res (deq(b)X)q

H and H’ are equivalent

Page 18: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing Linearizability---------------------------------- Definitions ---------------------------------------------------

A history H induces an irreflexive partial order H on methods: op1 H op2 ifس

res(op1) precedes inv(op2) in H. س If H is sequential, then H is a total order.

-----------------------------------------------------------------------------------------------------------------------

p

q

enq(a;ok)

enq(b;ok)

deq( ;a)

deq( ;b)

H’: inv(enq(a),X)p, inv(enq(b)X)q, res(enq(ok)X)p, res(enq(ok)X)q, inv(deq()X)p, inv(deq()X)q, res(deq(a)X)p, res (deq(b)X)q

enq(a) H’ deq(a)enq(a) H’ deq(b)enq(b) H’ deq(b)enq(b) H’ deq(a)

Page 19: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Formalizing Linearizability---------------------------------- Definitions -----------------------------------------------------.A set S of histories is prefix-closed if whenever H is in S, every prefix of H is also in Sس

A sequential specification for an object is a prefix-closed set of sequential histories forسthe object.

A sequential history H is legal if each object subhistory H|X belongs to the sequentialسspecification for X.

-----------------------------------------------------------------------------------------------------------------------

Linearizability

A history H is linearizable if it can be extended to a history H’ (by appending zero or more response events to H) such that:

L1 : complete(H’) is equivalent to some legal sequential history S, and L2 : H’ S.

Page 20: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Linearizabilityس Informally, extending H to H’ captures the idea that some pending invocations may

have taken effect even though their responses have not yet been returned to the caller. This is visible when some successive method call returns a value set by a pending invocation.

Extending H to H’ while restricting attention to complete(H’) makes it possible toسcomplete pending methods, or just to ignore them.

L1 states that complete(H’) is equivalent to an apparent sequential interleaving ofسmethod calls that does not violate the specification of the object.

L2 states that this apparent sequential interleaving respects the precedence orderingسof methods.

Page 21: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Linearizability...Then, let’s try to find Sس

p

q

enq(a;

enq(b;ok)

deq( ;

deq( ; b)

H: inv(enq(a),X)p, inv(enq(b)X)q, res(enq(ok)X)q, inv(deq()X)p, inv(deq()X)q, res (deq(b)X)q, inv(deq()X)q, res (deq(a)X)q

step1: extending...H’: inv(enq(a),X)p, res(enq(ok)X)p, inv(enq(b)X)q,

res(enq(ok)X)p, inv(deq()X)p, inv(deq()X)q, res (deq(b)X)q,

inv(deq()X)q, res (deq(a)X)q

deq( ; a)

Page 22: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Linearizabilitystep2: completing...

complete(H’): inv(enq(a),X)p, res(enq(ok)X)p, inv(enq(b)X)q, res(enq(ok)X)p, inv(deq()X)p, inv(deq()X)q, res (deq(b)X)q,

inv(deq()X)q, res (deq(a)X)qp

q

enq(a;ok)

enq(b;ok) deq( ; b) deq( ; a)

step3: let me see the partial order...

enq(a) H’ deq(b) H’ deq(a)

enq(b) H’ deq(b) H’ deq(a)

step4: ordering what is not yet ordered... S: enq(b) S enq(a) S deq(b) S deq(a) we got it!

Page 23: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

To do... :Linearizability has the following propertyس

Theorem : H is linearizable if and only if for each object x, H|x is linearizable.

To investigate if locality holds for the following alternative correctnessسcriteria:أ Sequential consistency: only L1أ Serizability: A history is serializable if it is equivalent to one in which transactions

appear to execute sequentially, that is, without interleaving. Transaction: finite sequence of methods to a set of objects

Page 24: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

Lecture 2: the “inside” view-point

speaker

sara tucci piergiovanniinstitution

università di roma “la sapienza”dipartimento di informatica e sistemistica

midlab laboratory

Page 25: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Objects Implementation .So, let us suppose now to have a concurrent object to implement, e.gس

stack, queue, etc.

how can we implement it? to get a linearizable execution, we can try toسuse some form of synchronization, e.g. to rule the access of the object by using of locks, mutex to define critical sections

The only one that can release the lock is the one who acquired the lockس

but we want also cope with failures...we want that a process gets aسresponse in a finite time, no matter the failures of others...

?So, if a process in the critical section failsس

Page 26: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Wait-free object implementation The meaning of wait-free computing is exaclty the following: eachس

process (that does not crash) calling a method must be able to get a response in a finite time no matter of how slow other proccesses are and failures of other processes

To introduce wait-free computing we will consider the wait-free سimplementation of two concurrent objectsأ A renaming object allows the processes to acquire new names from a smaller

name space despite possible process crashesأ A snapshot object provides the processes with an array-like data structure (with

one entry per process) offering two operations. The write operation allows a process to update its own entry. The snapshot operation allows a process to read all the entries in such a way that the reading of the whole array appears as it is was an atomic operation.

Page 27: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Setting We consider n processes, up to f are faulty (stop prematurely byس

crashing)

We will consider to use as building blocks for our implementation someسbasic concurrent objects, called atomic registers, that behave like registers accessed sequentially (so, we are implicitly assuming that the implementation of registers has been already done...later we will come back on this point)

Then processes can access these registers by invoking write() andسread() operations

Page 28: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

M-Renaming Problem Let us assume that the n processes have arbitrarily large (and distinct)س

initial names id1, . . . , idn [0, . . . , N − 1], where n <<< N. In the M-renaming problem, each process pi knows only its initial name idi, and the processes are required to get new names in such a way that the new names belong to the set {0, . . . , M − 1}, M<< N, and no two processes obtain identical names.

:More formally, the problem is defined by the three following propertiesس

Termination. Each correct process decides a new name.Validity.A decided name belongs to [0, . . . , M − 1].

Agreement.No two processes decide the same name.

Page 29: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Implementation Note that the renaming problem is a problem of allocation (one processس

for each name)We assume the presence of MultiWriterMultiReader registersس .We will see a simple and elegant algo by Moir–Andersonس It uses a mechanism called splitter that is particularly suited to wait-freeس

computing (the splitter has been used to implement wait-free mutual exclusion)

The renaming problem is trivial when no process cancommit a crash failure. Differently, it has been shownthat there is no wait-free solution to the M-renamingproblem when M < n+ f , where f is an upper bound

on the number of processes that can crash

Page 30: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Wait-free Splitter

X=undefined

Y=false

stop= empty

right=emtpy

down=empty

Page 31: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 32: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 33: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 34: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 35: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=true

stop= empty

right=emtpy

down=empty

Page 36: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=true

stop= empty

right=emtpy

down=empty

yawn

Page 37: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right=emtpy

down=empty

zzzz

Page 38: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right=emtpy

down=empty

zzzz

Page 39: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

zzzz

Page 40: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

zzzz

Page 41: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

awake!

Page 42: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

Page 43: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down={green}

Page 44: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down={green}

Page 45: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=red

Y=true

stop= empty

right={red}

down={green}

Note that green was slow and red was in late, nobody got stop

Page 46: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=undefined

Y=false

stop= empty

right=emtpy

down=empty

Page 47: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 48: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 49: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 50: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Page 51: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=true

stop= empty

right=emtpy

down=empty

Page 52: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=true

stop= {green}

right=emtpy

down=empty

Page 53: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=true

stop= {green}

right=emtpy

down=empty

Page 54: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Splitter

X=green

Y=true

stop= {green}

right={red, orange}

down=empty

Note that green was on time, red and orange was in late, nobody was slow

Page 55: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Moir-Anderson: the grid of Splittersn(n+1)/2 renaming splitters

Page 56: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

SnapshotThe object is made up of n SWMR atomic registers (one per process)س:Two operationsس

أ update(v) invoked by pi allows to update its register to the value vأ snapshot() returns the value of the n registers

All the operations appear as they were executed instantaneouslyس

The operation updates to inform others on its progress, the snapshotسallows a process to understand the what others are doing...

...collect vs snapshot, collect is not atomicس

Page 57: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Collect vs Snapshot

update(1, R1;ok)

update(2, R2;ok)

snapshot(?)possible values:

[000] [010] [012]

[000] [002] [012]

update(1, R1;ok)

update(2, R2;ok)

snapshot(?)

snapshot(?)

collect(?)

collect(?)

collect(?) possible values:

[000] [010] [002]

[000] [002] [010]

Page 58: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

A simple non-wait free algo

key mechanism:

double collect

update(1, R1;ok)

update(2, R2;ok)

collect(?) collect(?)possible values:

[000] [010] [002]collect(?) collect(?) it does not return!

How many times is this condition false?

Page 59: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

A wait free snapshot-Afek and et al.

key mechanism:

helping mechanism

double collect

If a process P sees two consecutive updates issued by the same process R, it knows that the second update began after its snapshot began..Then P borrows the snapshot that Q did here

Page 60: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

Lecture 3: the “global” look

speaker

sara tucci piergiovanniinstitution

università di roma “la sapienza”dipartimento di informatica e sistemistica

midlab laboratory

Page 61: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Wait-free computing issues The fundamental problem of wait-free computing is to characterizeس

circumstances under which synchronization problems have wait –free solutions and to derive efficient solutions when they exist.

To show that a wait-free implementation there exits, just draw an algoسand prove it.

?To show that such an implementation does not existس

Herlihy: tecnique to prove impossibility and an object hierarchyس

Page 62: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

The Relative Power of Objects:Fundamental problemس

أ Given two concurrent objects X and Y, does there exists a wait-free implementation of X by Y?

أ Thanks to Herhily classification of objects based on their synchronization power, we can derive impossibility: if for example we have two objects X and Y and Y has less synchronization power than X, then there exists no implementation of X by Y.

أ How to define the synchronization power of an object?

Page 63: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

The Consensus Number Each object is classified through its possibility of solving Consensus in aس

wait –free manner.

In particular, an object X has Consensus Number k, if withسobjects X and atomic registers (all initialized to appropriate values) it is possible to solve wait-free Consensus for k processes but not for k+1 processes.

For whom does not know Consensus: processes start with an inputسvalue and eventually agree on a common input value أ agreement: distinct processes never decide on distinct valuesأ wait-free: each process decides after a finite number of stepsأ validity: the common decision value d is the input of some process

Page 64: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Accessing Rules Defined by

the Consensus Protocol

Consensus26 6 75

6 6 6

ObjectObject

Page 65: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Wait- free Consensus26 6 75

26 26

ObjectObject

Page 66: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Objects and Consensus Numbers If there exits a wait-free implementation of an object X by Y, and Xس

has consensus number n, then Y has consesus number at least n

If an object X has consensus number n and an object Y has a consesusسnumber m<n, then there exists no wait-free implementation of X by Y in a system of k > m processes.

If two objects X and Y have consensus number n, then there exists aسwait-free implementation of X by Y (and viceversa) in a system with n processes.

If two objects X and Y have consensus number n , is it true that thereسexists no wait-free implementation of X by Y in a system of k>n processes? open issue...

Page 67: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Objects Classificationread-write register 1

list 2

stack 2

queue 2

test&set 2

fetch&add 2

swap 2

m-multipleassignment 2m-2

move and swap

augmentedqueue

compare&swap

fetch&cons

sticky byte

counters

1

atomic snapshot 1

Page 68: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Objects with Consensus number 1

Atomic registers, counters, other interfering objectsسthat don't return the old value (explained later)

-First observe that any type has consensus number at least 1, since 1سprocess consensus is trivial.

To prove that an object has consensus number 1, we should show thatسit is impossible to solve Consensus (by the object) among two processes (with initial values in the set {0,1})أ Then we show that an object has consensus number exactly 1, by running

FischerLynchPaterson with 2 processes.

Page 69: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Read-Write Registers & Consensus0 1

? ?

Read-Write Register

Read-Write Register

Page 70: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: assume otherwise

Read-Write Register

Read-Write Register

0 0

Read-Write Register

Read-Write Register

0 0

Let us assume that there exits a Consensus Protocol that can use only read() and write() operations

In this case the outcome should be:

Initial State (0,0)

Page 71: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: assume otherwise

Read-Write Register

Read-Write Register

Initial State (1,1)

1 1

Read-Write Register

Read-Write Register

1 1

In this case the outcome should be:

Page 72: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: assume otherwise

Read-Write Register

Read-Write Register

1 0

Read-Write Register

Read-Write Register

1

Initial State (1,0)

In this case the outcome should be:

Page 73: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: assume otherwise

Read-Write Register

Read-Write Register

1 0

Read-Write Register

Read-Write Register

0

Initial State (1,0)

In this case the outcome should be:

Page 74: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: assume otherwise

Read-Write Register

Read-Write Register

1 0

Read-Write Register

Read-Write Register

1 1

Read-Write Register

Read-Write Register

0 0

Initial State (1,0)

In this case the outcome could be:

or even:

Page 75: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: assume otherwise

Read-Write Register

Read-Write Register

0 1

Read-Write Register

Read-Write Register

0 0

Read-Write Register

Read-Write Register

1 1

Initial State (0,1)

In this case the outcome could be:

or even:

Page 76: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: reasoning about any protocolBivalent&Univalent States: .A protocol state is bivalent if both decision values are still possibleس

أ the outcome is not fixed (like for the (0,1) and (1,0) initial states) أ the protocol execution can be extended to yield a decision value but can also be

extended to yield the other value

A protocol state is univalent if all protocol executions yields to the sameسvalue أ the outcome is fixed even if not yet known

A 0-valent state yields to decide 0سA 1-valent state yields to decide 1س

Page 77: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

s’

Proof: reasoning about any protocol

()A “move” can be a read() or a write س

To reason about “any” protocol, we abstract the computation in this way:

we consider that Mr.Red and Mr.Green do “moves” against a protocol state. E.g. starting from the initial state either Mr. Red or Mr. Green do the first “move”, and we get in an other protocol state. At this point, again either Mr. Red or Mr. Green do the second “move” and so on...

s

s’’s

s’s

s’’’

s’v

sv

s’’s sv’

possible protocol executions

Page 78: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: reasoning about any protocol

Initial state

Final states

Page 79: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: reasoning about any protocol

decision:1 decision:0 decision:0 decision:1 decision:1 decision:0

Page 80: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof:reasoning about any protocol

decision:1 decision:0 decision:0 decision:1 decision:1 decision:0

bivalent states

Page 81: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: reasoning about any protocol

decision:1 decision:0 decision:0 decision:1 decision:1 decision:0

1-valent states

Page 82: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof:reasoning about any protocol

decision:1 decision:0 decision:0 decision:1 decision:1 decision:0

0-valent states

Page 83: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: reasoning about any protocolThe initial state is bivalent (by the fact that at least one failure may occur,

inputs are invisible and validity)

To solve consensus we have to reach a bivalent state C that has only univalent successors (otherwise we could stay bivalent forever and the protocol is not wait-free)

Now we assume that C has a 0-valent and a 1-valent successor produced by applying operations x and y of processes Mr.Red and Mr.Green:

Cx=0-valent and Cy=1-valent

Page 84: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: reasoning about any protocol

decision:1 decision:0 decision:0 decision:1 decision:1 decision:0

Bivalent C

Page 85: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: derive a contradiction Now, since we are looking at atomic registers, we have three casesس

consider cases:

أ (1) x and y are both readsأ (2) x is a read and y is a writeأ (3) x and y are both writes

Page 86: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: derive a contradiction(1) x and y are both readsس If read() comes first then the protocol decides 1س If read() comes first then the protocol decides 0

The idea is the following: to get an univalent state the two processes should decide who is the winner, who came first.

Then we start from C: Mr.red does the first move, this means that both should decide for 0. Then they both decide for 0 if Mr.Red comes before Mr.Green. Now, think that Mr.Green reads before Mr.Red. Now this order should lead to a decision opposite to the other....

Page 87: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: derive a contradictionBivalent CMr Green

reads first

1-valent state

Mr Red reads first

0-valent stateMr Red

reads 1-valent state

But for Mr Red these two states are indistinct (C=Cy): Mr Red cannot understand if Mr Green did it something or not before him...So, you can remove the green arrow and then get a contradiction!

We got that Cxy = 0-valent=Cyx=1-valent. Contradiction.

Page 88: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: derive a contradiction(1) x is a read() and y is a writeس If write() comes first then the protocol decides 1س If read() comes first then the protocol decides 0

Let us suppose that Mr.Red runs before Mr. Green. Then, both will decide for 0. Let us suppose now that Mr. Green comes first. Now they both will decide 1. However, for Mr.Green the state C is indistinguishable from Cx. So running Mr. Green to completion gives the same decision value from both Cyx and Cxy, another contradiction.

We got that Cxy = 0-valent=Cyx=1-valent. Contradiction.

Page 89: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Proof: derive a contradiction(1) x is a write() and y is a writeس If write() comes first then the protocol decides 1س If write() comes first then the protocol decides 0

Let us suppose that Mr.Red runs before Mr. Green. Then, both will decide for 0. Let us suppose now that Mr. Green comes first. Now they both will decide 1. However, for Mr.Green the state C is indistinguishable from Cx because Mr.Green overwrites on the value written by Mr.Red. Then we got that Cxy=Cy for Mr.Green. Another contradiction.

We got that Cxy = 0-valent=Cy=1-valent. Contradiction.

Page 90: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Summarizing and Generalizing The consensus protocol should allow all processes discovering who was the processس

that access the object first, then all processes decides the value of the process that won.

Suppose that an object T has a read operation that returns its state and one or moreسmodify-write operations that don't return anything (uninformative).

We'll say that the T operations are interfering if for any two operations x and yسeither: أ x and y commute: Cxy = Cyx. أ one between x and y overwrites the other: Cxy = Cy or Cyx =

Cx.

Any T object with all operations uninformative and interfering has consensus number 1سsince for any two operations either they commute or the overwriter can't detect that the first operation happened

Page 91: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Objects with Consensus Number 2 Now we will see what are the characteristics of objects with consensusس

number 2

For all these objects there exists a wait-free consensus protocol amongسtwo processes

أ registers with interfering non trivial read-modify-write operations (RMW registers) أ objects with non interfering operations: queue, stacks, lists

We derive also the intuition of the impossibility to solve consensusسamong n>2 processes using these objects

Page 92: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-trivial RMW Registers What does it mean having non-trivial operations? It means that thereس

exists an operation such that it returns the current value and writes a value obtained through a certain function that is not the identity

أ The operation takes 2 arguments:

ر Register rر Function f

أ The operation has the following effects:ر Returns value x of rر Replaces x with f(x): x f(x)x

Then, it is not a simple read (obtained if f were the identity), but a readسthat leaves an evidence...

Page 93: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-trivial RMW Registerstest&setس

أ The operation has the following effects:ر Returns value x of rر Replaces x with 1

fetch&incسأ The operation has the following effects:

ر Returns value x of rر Replaces x with x+1

Page 94: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-trivial RMW Registersswapس

أ The operation takes an additional argument yأ The operation has the following effects:

ر Returns value x of rر Replaces x with y

fetch&addسأ The operation takes an additional argument yأ The operation has the following effects:

ر Returns value x of rر Replaces x with x+y

Page 95: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-trivial RMW Registers?How a consesus protocol among two process can be designedس

....try to thinkسأ remember, both processes should discover who was the winner...أ first step: each one writes the proposed value in a registerأ second step: accessing the register object initialized to some value v with the

non-trivial operation أ who is the winner?

ر the one who reads vأ who is the loser?

ر the one who does not read vأ Note that both processes can deduce who is the loser and the winner, then they

go to the register to pick up the value proposed by the winner

Page 96: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Consensus among two processes

Two read-write

Registers

Two read-write

Registers

1 0

Initial State (1,0)

Non-trivial RMW register

Non-trivial RMW register

1 0v f(v)

Two read-write

Registers

Two read-write

Registers

1 1

winner loser

write write

read(1) read(1)

Page 97: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

What about Queues? By their consensus number, there exists a consensus protocol usingس

read/write registers and queues

Wait-free queue object with enqueue and dequeue operations, whereسdequeue returns empty if the queue is empty. To solve 2-process consensus with a wait-free queue:

أ Initialize the queue with a single value (it doesn't matter what the value is).أ A process wins if it successfully dequeues the initial value and loses if it gets

empty.

Page 98: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-trivial RMW Registers: no Consensus for n>2

?why a third process cannot understand who was the winnerسأ Let F be a set of functions such that for all fi and fj, either

ر They commute: fi(fj(x))=fj(fi(x))

ر They overwrite: fi(fj(x))=fi(x)

test&setسأ f(x)=1 f(f(x))=1 overwrite

swapسأ f(v,x)=x f(y’(f(y,x))=f(y’,x) overwrite

fetch&incسأ f(x)=x+1 f(f(x))=x+1+1 commutative

Page 99: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-trivial RMW Registers: no Consensus for n>2

The Impossibility Intuition for Non-trivial interefering RMWسأ Let us suppose that Mr.green accesses the object with an operation x and

Mr. Red with an operation y (e.g. both fethc&inc). The third process Mr. Orange that accesses (reading) the object after Mr.Green and Mr.Red cannot understand who was the winner between these two (in both cases, i.e. Mr. Red the winner, or Mr. Green the winner, the state is the same).

أ So if we run Mr. Orange to completion we get the same decision value after both Cx and Cy, which means that Cx and Cy can't be 0-valent and 1-valent. Contradiction.

Page 100: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

What about queues? Queues, stacks,lists are not interfering objects: no owerwriting andس

commutative operationsأ es enq(g)enq(r) enq(r)enq(g) enq(g)

they seems more powerful...if the Mr. Orange sees by dequeingسg,r or r,g it can understand who arrives first (Mr.Green in the first case, Mr.Red in the second)

But even for queues no wait-free Consensus implementation thereسexists for n>2, i.e. Mr. Orange is not able to understand who was the winner...why?

Page 101: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Non-interfering Queues: no consensus for n>2:Here we give the intuition behind the impossibilityس

Start from C enq(g) enq(r) (1-valent) and C enq(r) enq(g)س(0-valent) أ Run Mr.Red until its first deq() أ Run Mr.Green until it does its first deq() . أ Mr. Orange cannot distinguish between C, C enq(g) enq(r) and C

enq(r) enq(g).

Start from C deq() enq(r) and C enq(r) deq() on a non-emptyسqueue. أ To lose the trace of this order (we reach indistinguishable states), it suffices that

ony 2 witnessess (two dequeuers) fail. Then, the queue has number ≤ 2.

Page 102: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Objects with consensus number Augmented Queueس

أ Has operations enq(x) and peek(), which returns the first value enqueued but does not remove it. Protocol is to enq my input and then peek and return the first value into the queue.

Fetch-and-consسأ Returns old cdr and adds new car on to the head of a list. Use preceding protocol

where peek() = tail(car::cdr)

:Sticky bitsسأ Has write operation that fails unless register is in the initial state. Protocol is to

write my input and then return result of a read.

Compare-and-swapسأ has CAS(old, new) operation that writes new only if previous value = old. Use it to

build a sticky bit.

Page 103: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Consensus for n processes with CASn registers RiسFirst step: pi writes on its register Ri the value proposedس Second step: see if nobody have already access the object, if so, writeس

the identifier of i: CAS(-1,i) and set j to the previous value of the object j=CAS(-1,i).

If j==-1 (i is the first)س decide the value in Ri else

decide the value in Rj

Page 104: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

m-multiple assignment objectSnapshot meansس

أ Write any array elementأ Read multiple array elements atomically

:What about the dual problemسأ Write multiple array elements atomicallyأ Scan any array elements

This problem is called multiple assignmentس

It has been proved that m-multiple assignment has consensus numberس2m-2

Page 105: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

2-multiple assignment has at least number 2 Here we have a (large) collection of atomic registers augmented by an m-register writeس

operation that performs all the writes simultaneously.

The intuition for why this is helpful is that if Mr.Red writes atomically R1 and R whileسMr.Green writes atomically R2 and R, then any process can look at the state of R1, R2 and R and tell which write happened first: أ If Mr. Orange reads R1 = R2 =empty, then we don't care which went first, because the

Mr.Orange (or somebody else) already won. أ If Mr.Orange reads R1 = 1 and then R2 = empty, then Mr.Green went first. أ If Mr.Orange reads R2 = 2 and then R = empty, then Mr. Red went first. (This requires at

least one more read after checking the first case.) أ Otherwise if Mr.Orange see R1 = 1 and R2 = 2. Now it reads R: if it's 1, Mr. Green went

first, and vice versa.

Page 106: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Universality of Consensus ,Universality: any type that can implement n-process consensus canس

together with atomic registers, give a wait-free implementation of any object in a system with n processes.

the processes repeatedly use consensus to decide between candidateسhistories of the simulated object, and a process successfully completes an operation when its operation (tagged to distinguish it from other similar operations) appears in a winning history

Page 107: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Universality of Consensusس Have a n-process consensus protocol instance for each of a series of

phases 0, 1, ... . س The algorithm works as follows for a process p:

1. Post a list of the operation it wants to its register.2. Reads all the last-phase values and takes their max. 3. Runs the consensus protocol for the max phase to get the history decided on up

to that phase. 4. If the max phase history includes the process's pending operation, returns the

result that operation would have had in the winning history. 5. Otherwise, constructs a new history by appending all announced operations to

the previous history, and tries to win with that history in phase max+1. 6. Returns to step 2 if its operation doesn't make it into the winning history.

س This terminates because even if process i doesn't get its value into the winning history, eventually some other process will pick up the announced value and include it.

Page 108: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Summary?What have we learnedس

Per fare un albero ci vuole un seme, per fare un seme ci vuole un albero...questo loسsapevamo...ora sappiamo anche che

.Per fare un coda, una pila o una lista, non bastano uno o piu’ registri atomiciس

Per fare una coda in un sistema di 2 processi ci vogliono una o più pile. E’ vero cheسprendendo tante pile quante voglio non posso comunque fare una coda in un sistema con piu’ di due processi???? Nessuno lo ha mai dimostrato...

Per fare un compare&swap non solo non ce ne facciamo niente dei registri atomici maسneanche delle code...

Per fare un compare&swap ci vuole un oggetto con numero di consenso infinito...vaسbene consenso implementato tra un numero non noto di processi.

Page 109: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

June 8-9 2006 Seminars in Distributed Computing - Computing with Concurrent Objects

Sources M. Herlihy and J. Wing, "Linearizability: A Correctness Condition forس

Concurrent Objects", ACM Transactions on Programming Languages and Systems (TOPLAS), Volume 12 , Issue 3 (July 1990), pp. 463-492

M. Herlihy, “Wait-free synchronization” ACM Transactions onسProgramming Languages and Systems (TOPLAS) Volume 13 , Issue 1 (January 1991) pp: 124 – 149.

M. Raynal, “Wait-free computing: an introductory lecture” FutureسGeneration Computer Systems, Volume 21 , Issue 5 (May 2005) Special issue: Parallel computing technologies, pp: 655 – 663.

.M. Herlihy and N. Shavit. Concurrent Objects and Linearizabilityسwww.cs.tau.ac.il/~shanir/multiprocessor-synch-2003

Page 110: Computing with Concurrent Objects speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica

Grazie per l’attenzione!