[! A protocol for n threads:]
- All provide some value
- In the end, all agree on the same value (that was provided by at least one thread)
Requirements on consensus protocol
wait-free
Consensus returns in finite time for each thread
consistent
All threads decide the same value
valid
The common decision value is some thread’s input
public interface Consensus<T> {
T decide (T value);
}Linearizability of consnsus must be such that first thread’s decision is adopted for all threads.

Consensus number
Definition
A class solves -thread consensus if there exists a consensus protocol (algorithm) using any number of objects of class and any number of atomic registers.
Definition
Consensus number of : largest such that solves -thread consensus
Concrete examples / Important theorems
Important
Theorem I
Atomic Registers have consensus number 1. Corollary
There is no wait-free implementation of -thread consensus, , from read-write registers.
Proof todo
exam relevant
Important
Important
Theorem III
There is no wait-free implementation of a FIFO queue with atomic registers. Proof (by contradiction)
Why does this work? If one thread gets the red ball, the other gets the black ball.
Since the winner decides their own value and the loser can find the value in the array, they output the same value.
Note that the threads write their values to the array before dequeueing from the queue.
Now we have solved 2-thread consensus! BUT since we only used atomic-registers, this contradicts Theorem I.
So Theorem III must be true!
Comparison of synchronization numbers

Atomic Register: unable to “synchronize” two threads because there’s no way around Data Races It is impossible to implement TAS and CAS with Atomic Registers! that’s why extra hardware is needed
Why do we care?
- wait-free FIFO queues, wait-free RMW operations and CAS cannot be implemented with atomic registers! Otherwise, this would contradict the consensus number of Atomic Registers. (See Theorem III for an example)
TAS consensus

… It does not scale
TAS is inherently binary :
- It returns true/false, so a third one wouldn’t know which array index to return
- Even if it returned the previous value, it can only be 0 or 1 same issue The binary is not enough for n-thread consensus; same logic for AtomicInteger.getAndSet(int new) - It sets the given value and return the previous. It’s consensus number is also 2.
A global array for TAS and one for CAS…




