540 likes | 761 Views
Consensus Hierarchy Part 2. FIFO (Queue). tail. head. FIFO Object. Special case: empty queue. tail. head. Theorem:. A FIFO object has consensus number 2. Proof:. We can solve wait-free consensus using FIFO (and read/write) objects for 2 processes.
E N D
FIFO (Queue) tail head FIFO Object
Special case: empty queue tail head
Theorem: A FIFO object has consensus number 2 Proof: • 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
Proof-Part 1 A Wait-Free Consensus algorithm for 2 processors using a FIFO object (and read/write objects) tail head Initially:
Shared Memory Queue tail head Other Variables
Local variables :initial values for the consensus problem :resulting values for the consensus problem
Shared Memory Queue tail head Other Variables Initial values
Code for processor If then else //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
Example execution: Shared Memory Queue tail head
Suppose that accesses first the queue Shared Memory decides on its own value Queue tail head
Suppose that accesses second Shared Memory Queue Consensus Reached tail head decides on the other processor’s value
Proof-Part 2 We will prove: There is no wait-free consensus algorithm using only FIFO (and read-write) objects for Consider three processors (the same proof generalizes to more)
There is a bivalent initial configuration (we proved it before) We will show that every bivalent configuration has a processor which is not critical Therefore, we can construct an infinite execution with bivalent configurations where consensus is never reached
Assume for contradiction that all processors are critical univalent bivalent Possible executions univalent univalent
It cannot be that all have the same valence Contradiction valent bivalent valent valent valent
There must exist two processors with different valences bivalent univalent
Shared Memory Queue Queue Queue Read/Write Objects
Shared Memory Case: the processors access different objects Queue Queue bivalent Queue Read/Write Objects univalent Note: if an object was read/write the analysis is the similar
Two possible executions op Q2 op Q1 bivalent op Q2 op Q1 Impossible since univalent
Shared Memory Case: the processors access same object Queue Queue bivalent Queue Read/Write Objects univalent Note: if the object was read/write the analysis is the same as in the case with read/write objects
Subcase: deq/deq deq(Q) bivalent deq(Q) univalent
Queue Q before operations: deq(Q) deq(Q) bivalent deq(Q) deq(Q) Impossible since univalent
Subcase: deq/enq deq(Q) bivalent enq(Q,x) univalent
Suppose Q was not empty enq(Q,x) deq(Q) bivalent enq(Q,x) deq(Q) Impossible since univalent
Suppose Q was empty enq(Q,x) deq(Q) bivalent enq(Q,x) Impossible since univalent
Subcase: enq/enq enq(Q,a) bivalent enq(Q,b) univalent
Suppose Q was not empty enq(Q,b) enq(Q,a) bivalent enq(Q,b) enq(Q,a) univalent
enq(Q,b) Dequeue a Dequeue b enq(Q,a) bivalent enq(Q,b) enq(Q,a) Dequeue b Dequeue a univalent Impossible since
Explanation decides enq(Q,b) enq(Q,a) Suppose does not dequeue a bivalent A decision will be reached since the consensus algorithm is wait-free
decides enq(Q,b) enq(Q,a) contradiction bivalent decides enq(Q,b) enq(Q,a) The same value will be decided by , since sees the same shared memory values in both executions
In all cases we obtained contradiction; Therefore, there exists a processor which is not critical univalent bivalent univalent bivalent (not critical) univalent
Therefore, we can construct an execution bivalent bivalent bivalent Never ends Initial configuration Consensus can never be reached End of Theorem Proof
Compare&Swap Shared Memory Compare&Swap(X,A,B) { Temp X; If X==A then X B; Return Temp; } X
Theorem: The consensus number of the Compare&Swap object is Proof: Given processes, for any , we can solve wait-free consensus using a Compare&Swap object (and read/write objects)
A Wait-Free Consensus algorithm for n processors using a compare&swap object Local Memory Shared Memory First Initial value (compare&swap object) Final value
Code for processor If then else //am I the first? //yes, choose my value //no, choose the value of the first process which is stored in First Note: the algorithm uses a compare&swap and read/write objects
Example execution: Local Memory Shared Memory First
Suppose executes first Local Memory Shared Memory First Compare&Swap(First, ,0)
Suppose executes first Local Memory Shared Memory First Realizes it is first, decides on its own value
Suppose executes second Local Memory Shared Memory Compare&Swap(First, ,1) First
Suppose executes second Local Memory Shared Memory First Realizes is not first, decides on value of First
Similarly for Consensus has been reached Local Memory Shared Memory First Realizes is not first, decides on value of First
The algorithm is wait-free, since after the completion of the Compare&Swap operation, every processor decides (without considering what the other processors do)
Consensus Number Consensus Number of an object type: The maximum number of processes for which the object can be used to solve the wait-free consensus problem (together with read/write objects)
Object Type Consensus Number 1 Read/Write 2 FIFO Compare&Swap (infinity)
Simulation: Object Type B Object Type A Object Type A Read/Write Object Object of type A simulates object of Type B
Theorem: Objects of type A with consensus number cannot simulate another object of type B with consensus number Proof: Since otherwise, object A would have consensus number End of Proof
Universality Universal object: can simulate in a wait-free manner any other arbitrary object