Concurrency - The Relative Power of Primitive Synchronization Operations
CommentConsensus Numbers
1 | public interface Consensus<T> { |
- consistent: all threads decide the same value,
- valid: the common decision value is some thread’s input.
Def 5.1.1 A class C solves $n$-thread consensus if there exist a consensus protocol using any number of objects of class C and any number of atomic registers.
Def 5.1.2 The consensus number of a class C is the largest $n$ for which that class solves $n$-thread consensus. If no largest $n$ exists, we say the consensus number of the class if infinite.
Corollary 5.1.1 Suppose one can implement an object of class C from one or more objects of class D, together with some number of atomic registers. If class C solves $n$-consensus, then so does class D.
A protocol state is critical if:
- It is bivalent, and
- if any thread moves, the protocol state becomes univalent.
Lemma 5.1.3. Every wait-free consensus protocol has a critical state.
5.2 Atomic Registers
Whether we can solve consensus using atomic registers?
– no
There is no binary consensus protocol for two threads.
1 | public abstract class ConsensusProtocol<T> implements Consensus<T> { |
不是,你都有互斥的 Queue 了,那不是等同于作弊么
5.4 FIFO Queues
1 | public class QueueConsensus<T> extends ConsensusProtocol<T> { |
Corollary 5.4.1 It is impossible to construct a wait-free implementation of a queue, stack, priority queue, set, or list from a set of atomic registers.
5.5 Multiple Assignment Objects
5.6 Read-Modify-Write Operations
Many, if not all, of the classical synchronization operations provided by multiprocessors in hardware can be expressed as read-modify-write (RMW) operations, or, as they are called in their object form, read-modify-write registers.
1 | getAndSet(v); |
1 | class RMWConsensus extends ConsensusProtocol { |