1 consensus hierarchy part 2. 2 fifo (queue) fifo object headtail
TRANSCRIPT
1
Consensus HierarchyPart 2
2
FIFO (Queue)
FIFO Object
),( xQenq
Q
headtail
x
a
aQdeq )( x
b
ac b
c
bc
3
Special case: empty queue
)(Qdeq
tail head
4
Theorem: A FIFO object has consensusnumber 2
Proof:1. We can solve wait-free consensus using FIFO (and read/write) objects for 2 processes
2. We cannot solve wait-free consensus using FIFO (and read/write) variables for 3 or more processes
5
A Wait-Free Consensus algorithmfor 2 processors using a FIFO object(and read/write objects)
Initially:
tail head
0
Proof-Part 1
6
Shared Memory
Queue
Other Variables
0tail
head
7
0x 1x0p 1p
Local variables
}1,0{, ii yx
:initial values for the consensus problem
0y 1y
ix
iy:resulting values for the consensus problem
8
Shared Memory
Queue
Other Variables
0tail
head
1x
0xPrefer[0]Prefer[1]
Initial values
9
Code for processor ip }1,0{i
If then else
0)( Qdeq
ii xy ]1[ ipreferyi
//am I the first?
//yes, choose my value
//no, choose the other processor’s value
Note: the algorithm uses a FIFO object and read/write objects
ixiprefer ][
10
Example execution:
Shared Memory
Queue0tail
head
01 x
10 xPrefer[0]Prefer[1]
10 x
01 x
0p
1p
0y
1y
11
Suppose that accesses first the queue
Shared Memory
Queuetail
head
01 x
10 xPrefer[0]Prefer[1]
10 x
01 x
0p
1p
0y
01 y
1p
)(0 Qdeq
decides on its own value
12
Suppose that accesses second
Shared Memory
Queuetail
head
01 x
10 xPrefer[0]Prefer[1]
10 x
01 x
0p
1p
00 y
01 y
2p
decides on the other processor’s value
)(Qdeq
Consensus Reached
13
There is no wait-free consensusalgorithm using only FIFO(and read-write) objects for 3n
Consider three processors(the same proof generalizes to more)
Proof-Part 2
We will prove:
14
There is a bivalent initial configuration(we proved it before)
We will show that every bivalent configurationhas a processor which is not critical
Therefore, we can construct an infiniteexecution with bivalent configurations whereconsensus is never reached
15
Assume for contradiction that all processors are critical
C
0C
1C
1nC
bivalent0p
1p
2p
univalent
univalent
univalent
Possibleexecutions
16
bivalent
valent
It cannot be that all have the same valence
v
)1 or 0( v
valentv
valentv
valentv
Contradiction
C
0C
1C
2C
0p
1p
2p
17
There must exist two processors with different valences
valent-0
valent-1C
0C
1C
2C
bivalent0p
1p
2p
univalent
18
Shared Memory
1QQueue
2QQueue
zQQueue
Read/WriteObjects
19
Shared Memory
1QQueue
2QQueue
zQQueue
Read/WriteObjects
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2p
Case: the processors access different objects
0p
1p
Note: if an object was read/write the analysis is the similar
univalent
20
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2p
op Q
1
op Q2
op Q2
op Q1
C
C
1p
0p
valent-0
valent-1
CCp
2
Impossible since
Two possible executions
univalent
21
Shared Memory
1QQueue
QQueue
zQQueue
Read/WriteObjects
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2p
Case: the processors access same object
0p
1p
Note: if the object was read/write the analysisis the same as in the case with read/write objects
univalent
22
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
deq(
Q)
deq(Q)
Subcase: deq/deq
23
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
deq(
Q)
deq(Q)
deq(Q)
deq(Q)
C
C
1p
0p
valent-0
valent-1
CCp
2
Impossible since
Queue Q before operations: bc
a b
a d
a b
24
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
deq(
Q)
enq(Q,x)
Subcase: deq/enq
25
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
deq(
Q)
enq(Q,x)
enq(Q,x)
deq(Q)
C
C
1p
0p
valent-0
valent-1
CCp
2
Impossible since
Suppose Q was not empty a bc
a bx
a bx
26
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
deq(
Q)
enq(Q,x)
enq(Q,x)C 1pvalent-0
1
2
CCp
Impossible since
Suppose Q was empty
x
x
27
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
enq(
Q,a)
enq(Q,b)
Subcase: enq/enq
28
valent-0
valent-1
C
0C
1C
2C
bivalent0p
1p
2punivalent
enq(
Q,a)
enq(Q,b)
enq(Q,b)
enq(Q,a)
C
C
1p
0p
valent-0
valent-1
Suppose Q was not empty yx
yx
yx
a
a
b
b
29
valent-1
C 1C
2C
bivalent
0p
1p
2punivalent
enq(
Q,a
)
enq(Q,b) enq(Q,a)C 0p
valent-1
valent-0
0C enq(Q,b)C 1p
yxab b
0p
z w t w
1p0D
yxab z w t w
0p 1p1D
a
valent-0
Dequeue a Dequeue b
Dequeue b Dequeue a
Impossible since
10
2
DDp
30
C
bivalent
0p
enq(
Q,a
)
valent-0
0C enq(Q,b)C 1p
yxab b
0p
a
0 decidesvalent-0
Suppose does not dequeue a
0
A decision will be reached since the consensus algorithm is wait-free
0p
Explanation
0p
31
valent-1
C 1Cbivalent
0p
1p
enq(
Q,a
)
enq(Q,b) enq(Q,a)C 0p
valent-0
0C enq(Q,b)C 1p
yxab
0p
yxab
0p
0
0
valent-0
valent-1
The same value will be decided by ,since sees the same shared memory values in both executions
0p
decides 00p
decides 00p
contradiction
0
ba
ba
0p
32
In all cases we obtained contradiction;Therefore, there exists a processorwhich is not critical
C
0C
1C
1nC
bivalent0p
1p
1np
univalent
univalent
univalent
kC bivalent(not critical)
33
Therefore, we can construct an execution
0C 1C 2C
Initialconfiguration
0ip
1ip
2ip Never
ends
bivalent bivalent bivalent
Consensus can never be reached
End of Theorem Proof
34
Compare&Swap
Compare&Swap(X,A,B) { Temp X;
If X==A then X B;Return Temp; }
Shared Memory
X
35
Theorem: The consensus number ofthe Compare&Swap object is
Proof:
Given processes, for any , we can solve wait-free consensus using a Compare&Swap object(and read/write objects)
n n
36
A Wait-Free Consensus algorithm for n processors using a compare&swap object
Shared Memory
1nx
0x
1np
0p
1ny
0y
First
Local Memory
(compare&swap object)
Initial value
Final value
37
Code for processor ip }1,0{i
If then else
),,(& ii xFirstSwapComparev
ii xy
ii vy
//am I the first?
//yes, choose my value
Note: the algorithm uses a compare&swap and read/write objects
iv
//no, choose the value of the first process which is stored in First
38
Shared Memory00 x
0p0y
First
Local Memory
Example execution:
11 x1p
1y
02 x2p
2y
39
00 x0p
0y
Local Memory
Suppose executes first
11 x1p
1y
02 x2p
2y
2p
Compare&Swap(First, ,0)
Shared Memory
First
40
00 x0p
0y
Local Memory
Suppose executes first
11 x1p
1y
02 x2p
02 y
2p
0
Shared Memory
First
Realizes it is first, decides on its own value
41
00 x0p
0y
Local Memory
Suppose executes second
11 x1p
1y
02 x2p
1p
Compare&Swap(First, ,1)
Shared Memory
First0
02 y
42
00 x0p
0y
Local Memory
11 x1p
01 y
02 x2p
Shared Memory
First0
0
Realizes is not first, decides on value of First
02 y
Suppose executes second 1p
43
00 x0p
00 y
Local Memory
11 x1p
01 y
02 x2p
Shared Memory
First0
0
Realizes is not first, decides on value of First
02 y
Similarly for 0p Consensus has beenreached
44
The algorithm is wait-free, since after the completion of the Compare&Swap operation, every processor decides (without consideringwhat the other processors do)
45
Consensus HierarchyPart 3
46
Consensus Number
Consensus Number of an object type:
The maximum number of processes for which the object can be used tosolve the wait-free consensus problem(together with read/write objects)
47
Object Type Consensus Number
Read/Write 1
FIFO 2
Compare&Swap (infinity)
48
Simulation:Object Type B
Object Type A
Object Type A
Read/Write Object
Object of type A simulates object of Type B
49
Theorem:Objects of type A with consensus numbercannot simulate another object of type B withconsensus number
n
nm
Proof: Since otherwise, object A wouldhave consensus numberm
End of Proof
50
Universality
can simulate in a wait-free mannerany other arbitrary object
Universal object:
51
Objects with consensus number ncan simulate in a wait-free mannerany other arbitrary object of up toprocessors
n
We can show:
52
new-state
Compare&Swap
inv
responsebefore
new-stateinv
responsebefore
initial
head
anchor
Non-Blocking Simulation
53
new-state
Consensus Object
inv
responseafter
new-stateinv
responseafter
initial
Head
anchor
Non-Blocking Simulation
seq seq 1
54
new-stateinv
responseafter
Announce
seq
Wait-free Simulation