Concurrent Programming: Algorithms, Principles, PART 1: Lock-Based Synchronization and Foundations
Total Page:16
File Type:pdf, Size:1020Kb
Motivation Synchronization is Coming Back • Synchonization is coming back, but is it the same? But is it the Same? • Lots of new concepts and mechanisms since locks! Michel RAYNAL [email protected] • The multicore (r)evolution The synchronization world has changed Institut Universitaire de France • IRISA, Universit´ede Rennes, France Dpt of Computing, Polytechnic Univ., Hong Kong c Michel Raynal Synchronization is coming back! 1 c Michel Raynal Synchronization is coming back! 2 A recent book on the topic Part I Concurrent programming: Algorithms, Principles, PART 1: Lock-Based Synchronization and Foundations • Chapter 1: The Mutual Exclusion Problem by Michel Raynal • Chapter 2: Solving Exclusion Problem Springer, 515 pages, 2013 • Chapter 3: Lock-Based Concurrent Objects ISBN: 978-3-642-32026-2 6 Parts, composed of 17 Chapters Balance: algorithms vs foundations c Michel Raynal Synchronization is coming back! 3 c Michel Raynal Synchronization is coming back! 4 Part II Part III PART 3: Mutex-free Synchronization Chapter 5: Mutex-Free Concurrent Objects PART 2: On the Foundations Side: the Atomicity Concept • • Chapter 6: Hybrid Concurrent Objects • Chapter 4: • Chapter 7: Wait-Free Objects from Read/write Registers Only Atomicity: Formal Definition and Properties • Chapter 8: Snapshot Objects from Read/Write Registers Only • Chapter 9: Renaming Objects from Read/Write Registers Only c Michel Raynal Synchronization is coming back! 5 c Michel Raynal Synchronization is coming back! 6 Part IV Part V PART 5: On the Foundations Side: from Safe Bits to Atomic Registers PART 4: The Transactional Memory Approach • Chapter 11: Safe, Regular, and Atomic Read/Write Registers • Chapter 10: Transactional Memory • Chapter 12: From Safe Bits to Atomic Bits: a Lower Bound and an Optimal Construction • Chapter 13: Bounded Constructions of Atomic b-Valued Registers c Michel Raynal Synchronization is coming back! 7 c Michel Raynal Synchronization is coming back! 8 Part V Summary Computing Model: Processes and Concurrent Objects PART 6: On the Foundations Side: • the Computability Power of Concurrent Objects • Base read/write model, more powerful models • On the safety side: Linearizability • Chapter 14: Universality of Consensus • On the liveness side: Progress conditions • Chapter 15: The Case of Unreliable Base Objects • Mutex-free concurrent objects • Chapter 16: • Comuptability power, consensus number, etc. Consensus Numbers and the Consensus Hierarchy • Hybrid concurrent objects • Chapter 17: The Alpha(s) and Omega of Consensus • Conclusion c Michel Raynal Synchronization is coming back! 9 c Michel Raynal Synchronization is coming back! 10 Part I Asynchronous process model (1) • Computing model: n sequential processes Π = p1,...,pn (Turing machines) • Timing model: Asynchrony: No upper bound on the MODEL and DEFINITIONS time required to execute a computation step • Failure model ⋆ No failure ⋆ Crash failure c Michel Raynal Synchronization is coming back! 11 c Michel Raynal Synchronization is coming back! 12 Asynchronous process model (2) Asynchronous Base Communication Model (1) Shared memory provides processes with • Process crash: a process behaves according to its spec- ification until it possibly crashes, i.e., halts prematurely • Reliable Read/Write atomic registers (after it has crashed a process is definitely stopped) • Reliable Compare&Swap atomic registers • Terminology wrt a run: • Atomic means that: ⋆ A Correct process is a p that never crashes i ⋆ The operations on a register appear as if they have been executed sequentially ⋆ A Faulty process is a pi that crashes ⋆ Each operation appears as being executed instanta- neously at some point of the time line between its start event and its end event c Michel Raynal Synchronization is coming back! 13 c Michel Raynal Synchronization is coming back! 14 Atomic register Other base (hardware) operations READ: 2 READ: 1 WRITE: 1 WRITE: 2 READ: 2 WRITE: 3 • Test&set • Fetch&add Real time line • Compare&swap Valueis1 3 2 • LL/SC • Swap, Mem-to-Mem SWAP - Lamport L., On interprocess Communication (part 1: Basic Formalism, Part 2: • etc. Algorithms), Distributed Computing, 1(2):77-101, 1986 - Herlihy M.P. and Wing J.L., Linearizability: a Correctness Condition for Concurrent Objects. ACM Trans. on Programming Languages and Systems, 12(3):463-492, 1990 c Michel Raynal Synchronization is coming back! 15 c Michel Raynal Synchronization is coming back! 16 Structural view (Base level) Part II p1 local memory pi local memory pn local memory p1 pi pn On the SAFETY side Asynchronous shared memory Abstraction (could be shared disks, SAN) c Michel Raynal Synchronization is coming back! 17 c Michel Raynal Synchronization is coming back! 18 SAFETY PROPERTY Concurrent Object: example An object accessed by concurrent processes p LINEARIZABILITY p1 pi n - Herlihy M.P. and Wing J.M., Linearizability: a correctness condition for concurrent objects. ACM Toplas, 12(3):463- 492, 1990 Enqueue (v) r ← Dequeue () - Lamport L., On interprocess Communication (part 1: Basic Formalism, Part 2: Algorithms), Distributed Com- puting, 1(2):77-101, 1986 c Michel Raynal Synchronization is coming back! 19 c Michel Raynal Synchronization is coming back! 20 Sequential vs Concurrent (1) History (Run, Execution) Enq (a) Enq (b) Deq (a|b|c) ? SEQUENTIAL: p1 Enq (a) Enq (c) Enq (b) Deq(a) Deq (c) Enq (c) Deq(a|b|c) ? p2 CONCURRENT: Enq (a) Enq (b) Deq (a|b|c) ? p1 History H Inv (Enq(b)) Sequences of events Res (Enq(b)) Enq (c) Deq(a|b|c) ? p2 A history defines a partial order on the operations c Michel Raynal Synchronization is coming back! 21 c Michel Raynal Synchronization is coming back! 22 Two types of Concurrent Objects Example: Interactive consistency • A concurrent object encapsulates a particular synchro problem Each process pi proposes a value vi • Concurrent objects with a sequential specification Queue, file, graph, tree, stack, ... and has to decide a value such that: ⋆ Fifo queue: producer/consumer problem • Validity. Let D[1..n] be the vector decided by a process. ⋆ File (register): Readers/writers problem ∀i ∈ [1..n]: D[i] ∈ {vi, ⊥} and D[i]= vi if pi is correct • Concurrent objects with a not-sequential specification • Agreement. No two processes decide different vectors Rendezvous Object, Interactive Consistency, • Termination. Every correct process decides Non Blocking Atomic Commit Object, ... c Michel Raynal Synchronization is coming back! 23 c Michel Raynal Synchronization is coming back! 24 Linearizability Sequential vs Concurrent (2) Enq (a) Enq (b) Deq (a|b|c) ? An execution (or “history”) H is linearizable if the opera- p1 tions issued by the processes appear as if they have been executed in some sequential order that respects: Enq (c) Deq(a|b|c) ? p2 • The seq order in each process • The seq specification of the object The real-time order of the non-overlapping operations • Enq (a) Enq (c) Deq (b) Enq (b) Deq (a) c Michel Raynal Synchronization is coming back! 25 c Michel Raynal Synchronization is coming back! 26 Sequential vs Concurrent (3) Locality of the Linearizability property (1) Enq (a) Enq (b) Deq (a|b|c) ? p1 • A property P of a concurrent system is Local if the system as a whole satisfies P whenever each individual Enq (c) Deq (a|b|c) ? object satisfies P p2 Locality means that, given two objects X and Y , each satisfying the property P , the composite object [X,Y ] satisfies the property P • Linearizability is a local property (consistency criterion) Enq (a) Deq (a) Enq (c) Enq (b) Deq(c) c Michel Raynal Synchronization is coming back! 27 c Michel Raynal Synchronization is coming back! 28 Locality of the Linearizability property (2) Sequential Consistency • An execution (or “history”) H is sequentially consistent if the operations issued by the processes appear as if they have been executed in some sequential order that • Theorem: A history H is linearizable iff, for each object respects each process order and the seq specification X, H restricted to the operations on X is linearizable of every object Locality means that, given two linearizable objects X .Enq( ) and Y , the composite object [X,Y ] is linearizable Q a • It follows that each object can be implemented indepen- dently from the others (this is a fundamental property from both theoretical and practical point of views) Q.Enq(b) Q.Deq(b) • Sequential consistency, some forms of serializability are not local properties A ”witness” seq history: Q.Enq(b) Q.Enq(a) Q.Deq(b) c Michel Raynal Synchronization is coming back! 29 c Michel Raynal Synchronization is coming back! 30 Sequential Consistency is not Local Part III Q.Enq(a) Q′.Enq(b′) Q′.Deq(b′) Q′.Enq(a′) Q.Enq(b) Q.Deq(b) On the LIVENESS side • Q and Q′ are sequentially consistent PROGRESS CONDITIONS • the whole history H is not sequentially consistent Impossibility to produce a “witness” sequential history • See distributed caches c Michel Raynal Synchronization is coming back! 31 c Michel Raynal Synchronization is coming back! 32 Two cases MUTEX-FREEDOM • Reliable systems: • No code is protected by a critical section ⋆ Lock-based implementations ⋆ Progress conditions O.op1() by p1 O.op2(b) by p2 O.op1() by p3 ∗ Deadlock-freedom ∗ Starvation-freedom • Crash-prone systems: ⋆ Mutex-free implmentations R1 R3 R2R3R3 R2R3 R1 R2 R1 ⋆ Associated progress conditions c Michel Raynal Synchronization is coming back! 33 c Michel Raynal Synchronization is coming back! 34 Abortable object Obstruction-freedom • If an operation executes alone (concurrency-free con- • If an operation executes alone (concurrency-free con- text), it terminates and returns a correct value text), it terminates and returns a correct value • If an operation executes in a concurrency context, • If an operation executes in a concurrency context, it terminates and returns a correct value or it returns ⊥ and has no effect on the object ⋆ it can never termination ⋆ if it terminates, its result is correct This definition is different from the one used by Aguilera M.K., Frolund S., Hadzila- cos V., Horn S.L.