1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory:...
-
Upload
barbara-jackson -
Category
Documents
-
view
217 -
download
0
Transcript of 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory:...
1
Consensus HierarchyPart 1
2
Consensus in Shared Memory
Consider processors in shared memory:n
10,..., npp
which try to solve the consensus problem
3
0
1
0
0p
1p
2p
0
1
0
3p
4p
5p
Every process starts with an initial valuestored in local memory (0 or 1)
Shared memory
Local memory
Local memory
4
0
1
0
0p
1p
2p
0
1
0
3p
4p
5p
communication through shared memory
5
1
1
1
0p
1p
2p
1
1
1
3p
4p
5p
At the end of execution, every processhas decided the same value (0 or 1)
6
Validity condition:
If every process starts with the same value, the every process should decide that value
Additional condition:The decided value is one of the initial values
7
Wait-freedom in asynchronous systems:
A process should be able to finishexecution of an algorithmeven if all other processes fail
Wait-freedom captures:•Asynchronous executions•Crash failures
8
Object Types
Read/Write
FIFO
Compare&Swap
Test&Set
n-register assignment
9
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)
10
Object Type Consensus Number
Read/Write 1
FIFO, Test&Set 2
Compare&Swap (infinity)
n-register assignment 2n-2
11
int compare_and_swap ( int* register, int oldval, int newval) { int old_reg_val = *register; if (old_reg_val == oldval) *register = newval; return old_reg_val;}
int Test-and-Set(boolean lock) { boolean initial = lock; lock = true; return initial;}
(Shared ) boolean lock = false;
function Critical_Section() { while TestAndSet(lock) skip //spin until lock is acquired //Critical-section code - only one process can be in this section at a time begin { … } //end-of critical section – release lock lock = false //release lock when finished with the critical section }
Mutual Exclusion
12
Simulation:Object Type B
Object Type A
Object Type A
Read/Write Object
Object of type A simulates object of Type B(using auxiliary read/write objects)
13
Theorem:Objects of Type A with consensus numbercannot simulate in wait-free manner another object of Type B withconsensus number
n
nm
Proof: Since otherwise, object A wouldhave consensus numberm
End of Proof
14
can simulate in a wait-free mannerany other arbitrary object
Universal object:
Compare&SwapExample:
(infinity consensus number)
15
Objects with consensus number ncan simulate in a wait-free mannerany other arbitrary object of up toprocessors
n
We can show:
16
Read/Write
Shared Memory
Suppose that the sharedmemory can only be accessedthrough Read or Write operations
17
Theorem:
Proof of Theorem:
The consensus number of the Read/Write object is 1
Trivially, any consensus algorithm with 1 process using read/write variables is wait-free.
18
Wait-free consensus cannot besolved using only read/write objectsfor processors 2n
It remains to show:
We will show that any algorithmthat solves wait-free consensus for has an execution that never terminates
Approach:
2n
19
System configuration:
Is the set of all variables in the system, including local and shared
0
1
0
0p
1p
2p
0
1
0
3p
4p
5p
C
20
A distributed system execution can be always be viewed as a: sequence of configurations
0C fC1C 2C
Initialconfiguration
Finalconfiguration
0ip
1ip
2ip
Processor action: Read or Write
21
1
C
D
C D
1 0 1 0 0 0
bivalent
univalentunivalent
bivalent
Valence of system configurations
1-valent0-valent
Consensus value at possible execution paths
consensus reached consensusnot reached
consensus reached
22
A terminating execution:
0C 1C 2C
Initialconfiguration
0ip
1ip
2ip
Bivalent Bivalent Univalent
fC
Univalent
UnivalentBivalent
Finalconfiguration
23
To prove the theorem, we will show that there is always an executionwhere every configuration is bivalent
0C 1C 2C
Initialconfiguration
0ip
1ip
2ip
Bivalent Bivalent Bivalent
Never-ending execution
Bivalent
24
1
1
1
0p
1p
2p
1
0
0
0p
1p
2p
Similar configurations for processor 0p
23
198
76
23
198
76
Same shared variablesLocal variables of others may differ
1C 2C21
0
CCp
25
21 CCip
Lemma:If there exist univalent configurations
1C and such that2C
then if is -valentthen is -valent too
1C
2Cv
v
Proof of Lemma:
)1 or 0( v
26
1C
Univalent
Executionwith onlytaking actions
ip
ip
v v v
All possible executionsfrom 1C
final decision for each Possible execution
27
1C
Univalent
Executionwith onlytaking actions
ip
ip
v v v
2C
Univalent
Executionwith onlytaking actions
ip
ip
x x x
28
1C
Univalent
Executionwith onlytaking actions
ip
ip
v v v
2C
Univalent
Executionwith onlytaking actions
ip
ip
x vx x
21 CCip
29
1C
Univalent
Executionwith onlytaking actions
ip
ip
v v v
2C
Univalent
Executionwith onlytaking actions
ip
ip
21 CCip
v v v
End of Lemma Proof
30
Lemma:There exists a bivalentinitial configuration
Proof of Lemma:
31
Possible Initial Configurations
Shared Memory
Empty
Local Memory
10p
Initial Configuration1I
11p
1np 1
0
0I
0
0
0
01I
1
1
32
Possible Initial Configurations
Shared Memory
Empty
Local Memory
10p
11p
1np 1
0
0I
0
0
0
01I
1
1
0-valent 1-valent?
Initial Configuration1I
33
Possible Initial Configurations
Shared Memory
Empty
Local Memory
10p
11p
1np 1
0
0I
0
0
0
01I
1
1
0-valent 1-valent1-valent?
No, because 010
0
IIp
Initial Configuration1I
34
Possible Initial Configurations
Shared Memory
Empty
Local Memory
10p
11p
1np 1
0
0I
0
0
0
01I
1
1
0-valent 1-valent0-valent?
No, because 101
1
IIp
Initial Configuration1I
35
Possible Initial Configurations
Shared Memory
Empty
Local Memory
10p
11p
1np 1
0
0I
0
0
0
01I
1
1
0-valent 1-valentbivalent
End of Lemma Proof
Initial Configuration1I
36
Critical processor for a configuration:
the configuration is bivalent,and after the processor takes stepthe configuration becomes univalent
C C ipBivalent Univalent
37
Lemma:If is a bivalent configurationthen, there is at least one processorwhich is not critical
C
Proof of Lemma:
38
Assume for contradiction that all processors are critical
C
0C
1C
1nC
bivalent0p
1p
1np
univalent
univalent
univalent
Possibleexecutions
39
C
bivalent0p
1p
1np
valent
It cannot be that all have the same valence
v
)1 or 0( v
valentv
valentv
0C
1C
1nC
40
C
bivalent0p
1p
1np
valent
It cannot be that all have the same valence
v
)1 or 0( v
valentv
valentv
valentv
Contradiction 0C
1C
1nC
41
C
bivalent0p
jp
1np
There must exist two processors with different valences
iC
jC
ip
0C
1nC
valent-0
valent-1
42
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Case 1: suppose that they access different shared variables
Read x
Read y
x
y
ip
jp
43
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Read x
Read y
two possible executions
C
C
jp
ip
Read y
Read x
valent-0
valent-1
impossible since CC different valence
44
same result holds for any kind of operation (Read or Write) that the processors apply to x and y
45
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Case 2: suppose that they access the same shared variable
Read x
Read x
xip
jp
subcase: read/read
46
two possible executions
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Read x
Read x
C
C
jp
ip
Read x
Read x
valent-0
valent-1
impossible since CC different valence
47
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Read x
Write x
subcase: read/write
48
two possible executions
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Read x
Write x
C
C
jp
ip
Write x
Read x
valent-0
valent-1
impossible since j
p
CCj
different valence
49
subcase: write/write
C
bivalent
jp
iC
jC
ip
valent-0
valent-1
Write x
Write x
C
C
jp
ip
Write x
Write x
valent-0
valent-1
impossible since j
p
CCj
different valence
50
In all cases we obtained contradictionTherefore, there exists a processorwhich is not critical
C
0C
1C
1nC
bivalent0p
1p
1np
univalent
univalent
univalent
kC bivalent(not critical)
End of Lemma Proof
51
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