Computing with concurrent objects
Download
1 / 110

Computing with Concurrent Objects - PowerPoint PPT Presentation


  • 99 Views
  • Uploaded on

Computing with Concurrent Objects. speaker sara tucci piergiovanni institution università di roma “la sapienza” dipartimento di informatica e sistemistica midlab laboratory. Outline. Concurrent Objects Definition The “outside” view-point”

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Computing with Concurrent Objects' - alana-ochoa


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Computing with concurrent objects

Computing with Concurrent Objects

speaker

sara tucci piergiovanni

institution

università di roma “la sapienza”

dipartimento di informatica e sistemistica

midlab laboratory


Outline
Outline

  • 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 

Seminars in Distributed Computing - Computing with Concurrent Objects


Lecture1 the outside view point

Lecture1: the “outside” view-point

speaker

sara tucci piergiovanni

institution

università di roma “la sapienza”

dipartimento di informatica e sistemistica

midlab laboratory


What is an object
What is an object?

  • An objectin 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).

Seminars in Distributed Computing - Computing with Concurrent Objects


Pre and post conditions
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

method invocation

exception

p

enq(a;ok)

enq(b;ok)

deq( ;a)

deq( ;b)

deq()

time

method response

Seminars in Distributed Computing - Computing with Concurrent Objects


Concurrent model
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?

where is the trick?

p

method call

enq(a;ok)

deq( ;?)

enq(a;ok)

queue’s state

a

a

a

a

a

a

a

at the end of the invocation, the queue surely contains a, but during the invocation what did it happen? God knows

deq( ;?)

q

enq(b;ok)

Seminars in Distributed Computing - Computing with Concurrent Objects


The linearizability manifesto
The Linearizability Manifesto

  • The Linearizability Manifesto.

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

p

enq(a;ok)

deq( ;b)

deq( ;a)

q

enq(b;ok)

time

S

a

a

b

b

Seminars in Distributed Computing - Computing with Concurrent Objects


Linearizability scenario
Linearizability: scenario

  • Again, is this execution linearizable?

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

p

enq(a;ok)

enq(b;ok)

deq( ;a)

q

deq( ;c)

r

enq(c;ok)

deq( ;b)

S

c

c

a

a

c

b

a

a

b

Seminars in Distributed Computing - Computing with Concurrent Objects


Linearizability scenario1
Linearizability: scenario

  • Again, is this execution linearizable?

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

p

enq(b;ok)

enq(c;ok)

q

enq(a;ok)

deq( ;a)

r

deq( ;b)

deq( ;c)

S

b

b

b

no way...

c

c

a

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability
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 invocationand responseevents.

  • 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.

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

p

enq(a;ok)

t

res (enq(ok), X) p

H: inv (enq(a), X) p

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability1
Formalizing Linearizability

  • Concurrent execution example and related History

p

enq(a;ok)

deq( ;a)

deq( ;b)

q

enq(b;ok)

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability2
Formalizing Linearizability

  • Concurrent execution example and related History

p

enq(a;ok)

deq( ;a)

deq( ;b)

q

enq(b;ok)

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability3
Formalizing Linearizability

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

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

  • An invocation is pendingin 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.

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability4
Formalizing Linearizability

  • Concurrent execution example and related History

p

enq(a;ok)

deq( ;

deq( ;)

q

enq(b;ok)

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

matching

matching

pending

pending

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability5
FormalizingLinearizability

----------------------------------------- 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 equivalentif for every process p, H|p = H’|p.

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

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability6
Formalizing Linearizability

  • Sequential History H

p

enq(a;ok)

deq( ;a)

deq( ;b)

q

enq(b;ok)

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability7
Formalizing Linearizability

  • Concurrent History H’

p

enq(a;ok)

deq( ;a)

deq( ;b)

q

enq(b;ok)

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability8
Formalizing Linearizability

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

  • A history H induces an irreflexive partial order  Hon methods: op1  H op2 if res(op1) precedes inv(op2) in H.

  • If H is sequential, then  His a total order.

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

p

enq(a;ok)

deq( ;a)

deq( ;b)

q

enq(b;ok)

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)

Seminars in Distributed Computing - Computing with Concurrent Objects


Formalizing linearizability9
FormalizingLinearizability

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

  • A set S of histories is prefix-closedif whenever H is in S, every prefix of H is also in S.

  • A sequential specificationfor an object is a prefix-closed set of sequential histories for the object.

  • A sequential history H is legalif 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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Linearizability
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Linearizability1
Linearizability

  • Then, let’s try to find S...

p

enq(a;

deq( ;

deq( ; b)

deq( ; a)

q

enq(b;ok)

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Linearizability2
Linearizability

step2: 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)q

p

enq(a;ok)

deq( ; b)

deq( ; a)

q

enq(b;ok)

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)  Senq(a)  S deq(b)  Sdeq(a) we got it!

Seminars in Distributed Computing - Computing with Concurrent Objects


To do
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Lecture 2 the inside view point

Lecture 2: the “inside” view-point

speaker

sara tucci piergiovanni

institution

università di roma “la sapienza”

dipartimento di informatica e sistemistica

midlab laboratory


Objects implementation
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?

Seminars in Distributed Computing - Computing with Concurrent Objects


Wait free object implementation
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Setting
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

Seminars in Distributed Computing - Computing with Concurrent Objects


M renaming problem
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Implementation
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 can

commit a crash failure. Differently, it has been shown

that there is no wait-free solution to the M-renaming

problem when M < n+ f , where f is an upper bound

on the number of processes that can crash

Seminars in Distributed Computing - Computing with Concurrent Objects


Wait free splitter
Wait-free Splitter

X=undefined

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter1
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter2
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter3
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter4
Splitter

X=green

Y=true

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter5
Splitter

X=green

Y=true

stop= empty

right=emtpy

down=empty

yawn

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter6
Splitter

X=red

Y=true

stop= empty

right=emtpy

down=empty

zzzz

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter7
Splitter

X=red

Y=true

stop= empty

right=emtpy

down=empty

zzzz

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter8
Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

zzzz

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter9
Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

zzzz

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter10
Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

awake!

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter11
Splitter

X=red

Y=true

stop= empty

right={red}

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter12
Splitter

X=red

Y=true

stop= empty

right={red}

down={green}

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter13
Splitter

X=red

Y=true

stop= empty

right={red}

down={green}

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter14
Splitter

X=red

Y=true

stop= empty

right={red}

down={green}

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

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter15
Splitter

X=undefined

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter16
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter17
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter18
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter19
Splitter

X=green

Y=false

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter20
Splitter

X=green

Y=true

stop= empty

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter21
Splitter

X=green

Y=true

stop= {green}

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter22
Splitter

X=green

Y=true

stop= {green}

right=emtpy

down=empty

Seminars in Distributed Computing - Computing with Concurrent Objects


Splitter23
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Moir anderson the grid of splitters
Moir-Anderson: the grid of Splitters

n(n+1)/2 renaming splitters

Seminars in Distributed Computing - Computing with Concurrent Objects


Snapshot
Snapshot

  • The 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...

Seminars in Distributed Computing - Computing with Concurrent Objects


Collect vs snapshot
Collect vs Snapshot

snapshot(?)

snapshot(?)

possible values:

[000] [010] [012]

[000] [002] [012]

snapshot(?)

update(1, R1;ok)

update(2, R2;ok)

possible values:

[000] [010] [002]

[000] [002] [010]

collect(?)

collect(?)

collect(?)

update(1, R1;ok)

update(2, R2;ok)

Seminars in Distributed Computing - Computing with Concurrent Objects


A simple non wait free algo

How many times is this condition false?

it does not return!

A simple non-wait free algo

key mechanism:

double collect

collect(?)

collect(?)

possible values:

[000] [010][002]

collect(?)

collect(?)

update(1, R1;ok)

update(2, R2;ok)

Seminars in Distributed Computing - Computing with Concurrent Objects


A wait free snapshot afek and et al
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Lecture 3 the global look

Lecture 3: the “global” look

speaker

sara tucci piergiovanni

institution

università di roma “la sapienza”

dipartimento di informatica e sistemistica

midlab laboratory


Wait free computing issues
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

Seminars in Distributed Computing - Computing with Concurrent Objects


The relative power of 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 Yhas less synchronization power than X, then there exists no implementation of X by Y.

    • How to define the synchronization power of an object?

Seminars in Distributed Computing - Computing with Concurrent Objects


The consensus number
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Consensus
Consensus

75

6

26

Accessing Rules Defined by

the Consensus Protocol

Object

6

6

6

Seminars in Distributed Computing - Computing with Concurrent Objects


Wait free consensus
Wait- free Consensus

75

6

26

Object

26

26

Seminars in Distributed Computing - Computing with Concurrent Objects


Objects and consensus numbers
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...

Seminars in Distributed Computing - Computing with Concurrent Objects


Objects classification
Objects Classification

read-write

register

1

counters

1

atomic

snapshot

1

list

2

stack

2

queue

2

test&set

2

fetch&add

2

swap

2

m-multiple

assignment

2m-2

move

and swap

augmented

queue

compare&

swap

fetch&cons

sticky byte

Seminars in Distributed Computing - Computing with Concurrent Objects


Objects with consensus number 1
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Read write registers consensus
Read-Write Registers & Consensus

1

0

Read-Write Register

?

?

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof assume otherwise
Proof: assume otherwise

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

Initial State (0,0)

0

0

Read-Write Register

In this case the outcome should be:

0

0

Read-Write Register

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof assume otherwise1
Proof: assume otherwise

Initial State (1,1)

1

1

Read-Write Register

In this case the outcome should be:

1

1

Read-Write Register

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof assume otherwise2
Proof: assume otherwise

Initial State (1,0)

1

0

Read-Write Register

In this case the outcome should be:

1

Read-Write Register

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof assume otherwise3
Proof: assume otherwise

Initial State (1,0)

1

0

Read-Write Register

In this case the outcome should be:

Read-Write Register

0

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof assume otherwise4
Proof: assume otherwise

Initial State (1,0)

1

0

Read-Write Register

In this case the outcome could be:

Read-Write Register

1

1

or even:

0

0

Read-Write Register

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof assume otherwise5
Proof: assume otherwise

Initial State (0,1)

0

1

Read-Write Register

In this case the outcome could be:

Read-Write Register

0

0

or even:

1

1

Read-Write Register

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol
Proof: reasoning about any protocol

Bivalent&Univalent States:

  • A protocol state is bivalent ifboth 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

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol1
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’v

s

s’

possible protocol executions

s

s’’

sv

s

s’’

sv’

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol2

Final states

Proof: reasoning about any protocol

Initial state

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol3
Proof: reasoning about any protocol

decision:0

decision:1

decision:1

decision:0

decision:1

decision:0

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol4
Proof:reasoning about any protocol

bivalent states

decision:0

decision:1

decision:1

decision:0

decision:1

decision:0

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol5
Proof: reasoning about any protocol

1-valent states

decision:0

decision:1

decision:1

decision:0

decision:1

decision:0

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol6
Proof:reasoning about any protocol

0-valent states

decision:0

decision:1

decision:1

decision:0

decision:1

decision:0

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol7
Proof: reasoning about any protocol

The 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-valentandCy=1-valent

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof reasoning about any protocol8
Proof: reasoning about any protocol

Bivalent C

decision:0

decision:1

decision:1

decision:0

decision:1

decision:0

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof derive a contradiction
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof derive a contradiction1
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....

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof derive a contradiction2
Proof: derive a contradiction

Bivalent C

Mr Green reads first

Mr Red reads first

1-valent state

0-valent state

Mr 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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof derive a contradiction3
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Proof derive a contradiction4
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Summarizing and generalizing
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Objects with consensus number 2
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Non trivial rmw registers
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...

Seminars in Distributed Computing - Computing with Concurrent Objects


Non trivial rmw registers1
Non-trivial RMW Registers

  • test&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

Seminars in Distributed Computing - Computing with Concurrent Objects


Non trivial rmw registers2
Non-trivial RMW Registers

  • swap

    • 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

Seminars in Distributed Computing - Computing with Concurrent Objects


Non trivial rmw registers3
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Consensus among two processes
Consensus among two processes

Initial State (1,0)

Two read-write Registers

1

0

write

write

Non-trivial RMW register

1

0

v

f(v)

winner

loser

Two read-write Registers

1

1

read(1)

read(1)

Seminars in Distributed Computing - Computing with Concurrent Objects


What about queues
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Non trivial rmw registers no consensus for n 2
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)=1f(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

Seminars in Distributed Computing - Computing with Concurrent Objects


Non trivial rmw registers no consensus for n 21
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. Orangeto 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.

Seminars in Distributed Computing - Computing with Concurrent Objects


What about queues1
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. Orangesees 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. Orangeis not able to understand who was the winner...why?

Seminars in Distributed Computing - Computing with Concurrent Objects


Non interfering queues no consensus for n 2
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Objects with consensus number
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Consensus for n processes with cas
Consensus for n processes with CAS

  • n 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

Seminars in Distributed Computing - Computing with Concurrent Objects


M multiple assignment object
m-multiple assignment object

  • Snapshot 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

Seminars in Distributed Computing - Computing with Concurrent Objects


2 multiple assignment has at least number 2
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Universality of consensus
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

Seminars in Distributed Computing - Computing with Concurrent Objects


Universality of consensus1
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:

    • Post a list of the operation it wants to its register.

    • Reads all the last-phase values and takes their max.

    • Runs the consensus protocol for the max phase to get the history decided on up to that phase.

    • If the max phase history includes the process's pending operation, returns the result that operation would have had in the winning history.

    • 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.

    • 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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Summary
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.

Seminars in Distributed Computing - Computing with Concurrent Objects


Sources
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

Seminars in Distributed Computing - Computing with Concurrent Objects



ad