Declarative semantics for concurrency. 28 August 2017

Size: px
Start display at page:

Download "Declarative semantics for concurrency. 28 August 2017"

Transcription

1 Declarative semantics for concurrency Ori Lahav Viktor Vafeiadis 28 August 2017

2 An alternative way of defining the semantics 2 Declarative/axiomatic concurrency semantics Define the notion of a program execution (generalization of an execution trace) Map a program to a set of executions Define a consistency predicate on executions Semantics = set of consistent executions of a program Exception: catch-fire semantics Existence of at least one bad consistent execution implies undefined behavior.

3 Executions 3 Events Reads, Writes, Updates, Fences Relations Program order, po (also called sequenced-before, sb) Reads-from, rf W x 0 W y 0 W x 1 R x 1 rf po R y 0 rf R y 1 R x 0 rf W y 1

4 Executions 4 Definition (Label) A label has one of of the following forms: R x v r W x v w U(x v r v w ) F where x Loc and v r, v w Val. Definition (Event) An event is a triple id, i, l where id N is an event identifier, i Tid {0} is a thread identifier, and l is a label.

5 Executions 5 Definition (Execution graph) An execution graph is a tuple E, po, rf where: E is a finite set of events po ( program order ) is a partial order on E rf ( reads-from ) is a binary relation on E such that: For every w, r rf typ(w) {W, U} typ(r) {R, U} loc(w) = loc(r) valw (w) = val r (r) rf 1 is a function (that is: if w 1, r, w 2, r rf then w 1 = w 2 )

6 Some notations 6 Let G = E, po, rf be an execution graph. G.E = E G.po = po G.rf = rf G.R = {r E typ(r) = R typ(r) = U} G.W = {w E typ(w) = W typ(w) = U} G.RMW = {u E typ(u) = U} G.F = {f E typ(f ) = F} G.R x = G.R {r E loc(r) = x}...

7 Mapping programs to executions: Example 7 Store buffering (SB) x := 1 a := y x = y = 0 y := 1 b := x W x 0 W y 0 W x 0 W y 0 W x 0 W y 0 W x 1 W y 1 W x 1 W y 1 W x 1 W y 1 R y 0 R x 0 R y 1 R x 1 R y 0 R x 42

8 Mapping programs to executions: Definition 8 The thread subsystem associates a sequential execution graph to every command. A program execution is obtained by joining the sequential execution graphs of the constituent threads. Definition An execution graph G is called sequential if the following hold: tid(a) = 0 for every a G.E G.po is a total order on G.E G.rf =

9 From commands to sequential execution graphs 9 Initial execution graph: G - the empty graph silent c, s ε c, s c, s, G = c, s, G non-silent c, s l c, s l ε a = n, 0, l n {id(b) b G.E} c, s, G = c, s, Add(G, a) where Add(G, a) is the execution graph G given by: G.E = G.E {a} G.po = G.po (G.E {a}) G.rf = G.rf Definition (Execution graph of a command) G is a an execution graph of a command c with a final store s if c, s 0, G = skip, s, G.

10 Mapping programs to executions: Definition 10 Definition (Thread restriction) Given i Tid and an execution graph G, G i denotes the sequential execution graph obtained by restricting G to the events {a G.E tid(a) = i}, modifying their thread identifiers to 0, and discarding all rf-edges. Definition (Execution graph of a program) G is an execution graph of a program P (with an outcome O) if G i is an execution of P(i) (with final store O(i)) for every i Tid.

11 Consistency predicate 11 Let X be some consistency predicate (on execution graphs) Definition (Allowed outcome under a declarative model) An outcome O is allowed for a program P under X if there exists an execution graph G such that: G is an execution graph of P with outcome O. G is X-consistent. Exception: catch-fire semantics... or if there exists an execution graph G such that: G is an execution graph of P. G is X-consistent. G is bad.

12 Completeness 12 The most basic consistency condition: Definition (Completeness) An execution graph G is called complete if codom(g.rf) = G.R i.e., every read reads from some write.

13 Sequential consistency 13 the result of any execution is the same as if the operations of all the processors were executed in some sequential order, respecting the order specified by the program [Lamport, 1979]

14 Sequential consistency [Lamport] 14 Definition Let sc be a total order on G.E. G is called SC-consistent wrt sc if the following hold: If a, b G.po then a, b sc. If a, b G.rf then a, b sc and there does not exist c G.W loc(b) such that a, c sc and c, b sc. Definition An execution graph G is called SC-consistent if the following hold: G is complete. G is SC-consistent wrt some total order sc on G.E.

15 SB example 15 Store buffering (SB) x := 1 a := y x = y = 0 y := 1 b := x Allowed W x 0 W y 0 Forbidden W x 0 W y 0 W x 1 W y 1 W x 1 W y 1 R y 0 R x 1 R y 0 R x 0

16 Sequential consistency (Alternative) 16 Definition (Modification order (aka coherence order)) mo is called a modification order for an execution graph G if mo = x Loc mo x where each mo x is a total order on G.W x. Definition (Alternative SC definition) An execution graph G is called SC-consistent if the following hold: G is complete There exists a modification order mo for G such that G.po G.rf mo rb is acyclic where: rb = G.rf 1 ; mo \ id (from-reads / reads-before)

17 SB example 17 Store buffering (SB) x := 1 a := y x = y = 0 y := 1 b := x Allowed W x 0 W y 0 Forbidden W x 0 W y 0 W x 1 W y 1 W x 1 W y 1 R y 0 R x 1 R y 0 R x 0

18 Equivalence 18 Theorem The two SC definitions are equivalent. Proof (sketch). Lamport SC alternative SC: Take mo x = [W x ]; sc; [W x ]. Then, G.po G.rf mo rb sc. Alternative SC Lamport SC: Take sc to be any total order extending G.po G.rf mo rb.

19 Relaxing sequential consistency 19 SC is very expensive to implement in hardware. It also forbids various optimizations that are sound for sequential code. What most hardware guarantee and compilers preserve is SC-per-location (aka coherence). Definition An execution graph G is called coherent if the following hold: G is complete For every location x, there exists a total order sc x on all accesses to x such that: If a, b [RWx ]; G.po; [RW x ] then a, b sc x If a, b [Wx ]; G.rf; [R x ] then a, b sc x and there does not exist c G.W x such that a, c sc x and c, b sc x.

20 Alternative definition of coherence I 20 SC: po rf mo rb is acyclic COH: po loc rf mo rb is acyclic Definition Let mo be a modification order for an execution graph G. G is called coherent wrt mo if G.po loc G.rf mo rb is acyclic (where rb = G.rf 1 ; mo \ id). Theorem An execution graph G is coherent iff the following hold: G is complete G is coherent wrt some modification order mo for G.

21 Bad patterns I 21 R x rf po W x no-future-read a := x / 1 x := 1 rf U x rmw-1 r := CAS(x, 1, 1) / 1 Recall: W is either a write or an RMW. R is either a read or an RMW.

22 Bad patterns II 22 x := 1 x := 2 a := x / 2 a := x / 1 W x mo po W x coherence-ww W x mo W x rf po R x coherence-wr W x rf mo R x W x coherence-rw W x W x rf mo rf R x R x coherence-rr po po

23 Bad patterns III 23 W x mo rf rmw-2 U x mo mo W x W x U x rf atomicity In coherent executions, an RMW event may only read from its immediate mo-predecessor.

24 Alternative definition of coherence II 24 Theorem Let mo be a modification order for an execution graph G. G is coherent wrt mo iff the following hold: rf; po is irreflexive. mo; po is irreflexive. mo; rf; po is irreflexive. rf 1 ; mo; po is irreflexive. rf 1 ; mo; rf; po is irreflexive. rf is irreflexive. mo; rf is irreflexive. rf 1 ; mo; mo is irreflexive. (no-future-read) (coherence-ww) (coherence-rw) (coherence-wr) (coherence-rr) (rmw-1) (rmw-2) (rmw-atomicity)

25 Examples (aka litmus tests ) 25 Coherence test x := 1 a := x / 2 x = 0 x := 2 b := x / 1 Store buffering x := 1 a := y /0 x = y = 0 y := 1 b := x /0

26 Atomicity 26 Parallel increment x = 0 a := FAA(x, 1) b := FAA(x, 1) Guarantees that a = 1 b = 1. Can we implement locks in this semantics? Spinlock implementation lock(l) : r := 0; while r do r := CAS(l, 0, 1) unlock(l) : l := 0

27 Implementing locks? 27 Under COH, the spinlock implementation does not guarantee mutual exclusion. Spinlock implementation lock(l) : r := 0; while r do r := CAS(l, 0, 1) unlock(l) : l := 0 Lock example lock(l) x := 1 a := y /0 unlock(l) lock(l) y := 1 b := x /0 unlock(l)

28 Message passing More generally, COH is often too weak: x := 42; y := 1 x = y = 0 a := y; while a do a := y; b := x /0 x := 42; y := 1 x = y = 0 a := y; /1 b := x /0 MP is a common programming idiom. How can we disallow the weak behavior? 28

29 Supporting message passing 29 W x mo W x rf po R x coherence-wr W x mo W x rf (po rf) + R x coherence-wr Solution: Strengthen the notion of an observed write. In other words, make rf-edges synchronizing.

30 Release/acquire (RA) memory model 30 SC: po rf mo rb is acyclic COH: po loc rf mo rb is acyclic RA: (po rf) + loc mo rb is acyclic Definition Let mo be a modification order for an execution graph G. G is called RA-consistent wrt mo if (po rf) + loc mo rb is acyclic for some modification order mo for G (where rb = G.rf 1 ; mo \ id). Definition An execution graph G is RA-consistent if the following hold: G is complete G is RA-consistent wrt some modification order mo for G.

31 Alternative definition of RA consistency 31 Theorem Let mo be a modification order for an execution graph G. G is RA-consistent wrt mo iff the following hold: (po rf) + is irreflexive. mo; (po rf) + is irreflexive. rf 1 ; mo; (po rf) + is irreflexive. rf 1 ; mo; mo is irreflexive. (no-future-read) (coherence-ww) (coherence-wr) (rmw-atomicity)

32 Hardware implementation of RA 32 RA is cheaper to implement than SC, but some architectures still require some fences. On Power, a lightweight fence (lwsync) suffices, and RA is still cheaper than SC. Release write lwsync ; store Acquire read load ; lwsync (or load ; bc ; isync) ARMv7 is like Power, but has no lightweight fence. Release write dmb ; store Acquire read load ; dmb (or load ; bc ; isb) ARMv8 has special release/acquire accesses. Alternative: acquire read load ; dmb ld On TSO, no fences are needed. (See also exercise.)

33 Mixing the models 33 COH < RA < SC Revisit the MP idiom: x := 42 y := 1 a := y while a do a := y b := x /0 We only need the last read of y to synchronize. Idea: introduce access modes. x := rlx 42 y := rel 1 a := y rlx while a do a := y a := y acq b := x rlx /0

34 Happens-before 34 Each memory accesses has a mode: Reads: rlx or acq Writes: rlx or rel RMWs: rlx, acq, rel or acq-rel Strength order is given by (the transitive closure of): Synchronization: rlx acq rel acq-rel Happens-before: G.sw = [W rel ]; G.rf; [R acq ] G.hb = (G.po G.sw) +

35 Towards C/C++11 memory model 35 SC: po rf mo rb is acyclic COH: po loc rf mo rb is acyclic RA: (po rf) + loc mo rb is acyclic C11: hb loc rf mo rb is acyclic Definition Let mo be a modification order for an execution graph G. G is called C11-consistent wrt mo if hb loc rf mo rb is acyclic (where rb = G.rf 1 ; mo \ id). Definition An execution graph G is C11-consistent if the following hold: G is complete G is C11-consistent wrt some modification order mo for G.

36 The C/C++11 memory model 36 nonatomic relaxed release/ acquire sc The full C/C++11 is more general: Non-atomics for non-racy code (the default!) Four types of fences for fine grained control SC accesses to ensure sequential consistency if needed More elaborate definition of sw ( release sequences )

37 Summary 37 A declarative approach for (weak) concurrency semantics Uniformly and modularly handle various models Important weakenings of SC (coherence, RA) with alternative formulations based on bad patterns Introduction to the C/C++11 memory model

38 Exercise: Extended coherence order 38 Let G be a coherent execution wrt some modification order mo for G. Let eco = (rf mo rb) Does eco totally order all accesses to a given location x? 2. Provide a simplification of eco that avoids the use of transitive closure.

39 Exercise: RA vs. TSO 39 Do RA and TSO have the same behaviors? 1. Construct a program with two threads that has different outcomes under TSO and RA. 2. Construct a program without write-write races that distinguishes the two models.

40 Exercise: Write-before 40 Let G be a complete execution without RMW events and let: wb = [W]; (po rf) + loc ; [W] ([W]; (po rf) + loc ; rf 1 ; [W]\id) 1. Show that G is RA-consistent iff wb is acyclic. 2. (Optional, difficult) Extend the definition of wb to work for executions with RMW events. 3. (Optional, difficult) Can one define an analogue wb relation in terms of just G, such that G is SC-consistent iff wb is acyclic?

Taming release-acquire consistency

Taming release-acquire consistency Taming release-acquire consistency Ori Lahav Nick Giannarakis Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) POPL 2016 Weak memory models Weak memory models provide formal sound semantics

More information

An introduction to weak memory consistency and the out-of-thin-air problem

An introduction to weak memory consistency and the out-of-thin-air problem An introduction to weak memory consistency and the out-of-thin-air problem Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) CONCUR, 7 September 2017 Sequential consistency 2 Sequential

More information

Effective Stateless Model Checking for C/C++ Concurrency

Effective Stateless Model Checking for C/C++ Concurrency 17 Effective Stateless Model Checking for C/C++ Concurrency MICHALIS KOKOLOGIANNAKIS, National Technical University of Athens, Greece ORI LAHAV, Tel Aviv University, Israel KONSTANTINOS SAGONAS, Uppsala

More information

Repairing Sequential Consistency in C/C++11

Repairing Sequential Consistency in C/C++11 Technical Report MPI-SWS-2016-011, November 2016 Repairing Sequential Consistency in C/C++11 Ori Lahav MPI-SWS, Germany orilahav@mpi-sws.org Viktor Vafeiadis MPI-SWS, Germany viktor@mpi-sws.org Jeehoon

More information

Repairing Sequential Consistency in C/C++11

Repairing Sequential Consistency in C/C++11 Repairing Sequential Consistency in C/C++11 Ori Lahav MPI-SWS, Germany orilahav@mpi-sws.org Viktor Vafeiadis MPI-SWS, Germany viktor@mpi-sws.org Jeehoon Kang Seoul National University, Korea jeehoon.kang@sf.snu.ac.kr

More information

Program logics for relaxed consistency

Program logics for relaxed consistency Program logics for relaxed consistency UPMARC Summer School 2014 Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) 1st Lecture, 28 July 2014 Outline Part I. Weak memory models 1. Intro

More information

Taming Release-Acquire Consistency

Taming Release-Acquire Consistency Taming Release-Acquire Consistency Ori Lahav Nick Giannarakis Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS), Germany {orilahav,nickgian,viktor}@mpi-sws.org * POPL * Artifact Consistent

More information

Relaxed Memory: The Specification Design Space

Relaxed Memory: The Specification Design Space Relaxed Memory: The Specification Design Space Mark Batty University of Cambridge Fortran meeting, Delft, 25 June 2013 1 An ideal specification Unambiguous Easy to understand Sound w.r.t. experimentally

More information

Repairing Sequential Consistency in C/C++11

Repairing Sequential Consistency in C/C++11 Repairing Sequential Consistency in C/C++11 Ori Lahav MPI-SWS, Germany orilahav@mpi-sws.org Chung-Kil Hur Seoul National University, Korea gil.hur@sf.snu.ac.kr Viktor Vafeiadis MPI-SWS, Germany viktor@mpi-sws.org

More information

Reasoning about the C/C++ weak memory model

Reasoning about the C/C++ weak memory model Reasoning about the C/C++ weak memory model Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) 13 October 2014 Talk outline I. Introduction Weak memory models The C11 concurrency model

More information

The C1x and C++11 concurrency model

The C1x and C++11 concurrency model The C1x and C++11 concurrency model Mark Batty University of Cambridge January 16, 2013 C11 and C++11 Memory Model A DRF model with the option to expose relaxed behaviour in exchange for high performance.

More information

On Parallel Snapshot Isolation and Release/Acquire Consistency

On Parallel Snapshot Isolation and Release/Acquire Consistency On Parallel Snapshot Isolation and Release/Acquire Consistency Azalea Raad 1, Ori Lahav 2, and Viktor Vafeiadis 1 1 MPI-SWS, Kaiserslautern, Germany 2 Tel Aviv University, Tel Aviv, Israel {azalea,viktor}@mpi-sws.org

More information

C11 Compiler Mappings: Exploration, Verification, and Counterexamples

C11 Compiler Mappings: Exploration, Verification, and Counterexamples C11 Compiler Mappings: Exploration, Verification, and Counterexamples Yatin Manerkar Princeton University manerkar@princeton.edu http://check.cs.princeton.edu November 22 nd, 2016 1 Compilers Must Uphold

More information

Overhauling SC atomics in C11 and OpenCL

Overhauling SC atomics in C11 and OpenCL Overhauling SC atomics in C11 and OpenCL John Wickerson, Mark Batty, and Alastair F. Donaldson Imperial Concurrency Workshop July 2015 TL;DR The rules for sequentially-consistent atomic operations and

More information

COMP Parallel Computing. CC-NUMA (2) Memory Consistency

COMP Parallel Computing. CC-NUMA (2) Memory Consistency COMP 633 - Parallel Computing Lecture 11 September 26, 2017 Memory Consistency Reading Patterson & Hennesey, Computer Architecture (2 nd Ed.) secn 8.6 a condensed treatment of consistency models Coherence

More information

Multicore Programming: C++0x

Multicore Programming: C++0x p. 1 Multicore Programming: C++0x Mark Batty University of Cambridge in collaboration with Scott Owens, Susmit Sarkar, Peter Sewell, Tjark Weber November, 2010 p. 2 C++0x: the next C++ Specified by the

More information

The C/C++ Memory Model: Overview and Formalization

The C/C++ Memory Model: Overview and Formalization The C/C++ Memory Model: Overview and Formalization Mark Batty Jasmin Blanchette Scott Owens Susmit Sarkar Peter Sewell Tjark Weber Verification of Concurrent C Programs C11 / C++11 In 2011, new versions

More information

RELAXED CONSISTENCY 1

RELAXED CONSISTENCY 1 RELAXED CONSISTENCY 1 RELAXED CONSISTENCY Relaxed Consistency is a catch-all term for any MCM weaker than TSO GPUs have relaxed consistency (probably) 2 XC AXIOMS TABLE 5.5: XC Ordering Rules. An X Denotes

More information

Load-reserve / Store-conditional on POWER and ARM

Load-reserve / Store-conditional on POWER and ARM Load-reserve / Store-conditional on POWER and ARM Peter Sewell (slides from Susmit Sarkar) 1 University of Cambridge June 2012 Correct implementations of C/C++ on hardware Can it be done?...on highly relaxed

More information

Overview: Memory Consistency

Overview: Memory Consistency Overview: Memory Consistency the ordering of memory operations basic definitions; sequential consistency comparison with cache coherency relaxing memory consistency write buffers the total store ordering

More information

Hardware models: inventing a usable abstraction for Power/ARM. Friday, 11 January 13

Hardware models: inventing a usable abstraction for Power/ARM. Friday, 11 January 13 Hardware models: inventing a usable abstraction for Power/ARM 1 Hardware models: inventing a usable abstraction for Power/ARM Disclaimer: 1. ARM MM is analogous to Power MM all this is your next phone!

More information

Foundations of the C++ Concurrency Memory Model

Foundations of the C++ Concurrency Memory Model Foundations of the C++ Concurrency Memory Model John Mellor-Crummey and Karthik Murthy Department of Computer Science Rice University johnmc@rice.edu COMP 522 27 September 2016 Before C++ Memory Model

More information

CS5460: Operating Systems

CS5460: Operating Systems CS5460: Operating Systems Lecture 9: Implementing Synchronization (Chapter 6) Multiprocessor Memory Models Uniprocessor memory is simple Every load from a location retrieves the last value stored to that

More information

Library Abstraction for C/C++ Concurrency

Library Abstraction for C/C++ Concurrency Library Abstraction for C/C++ Concurrency Mark Batty University of Cambridge Mike Dodds University of York Alexey Gotsman IMDEA Software Institute Abstract When constructing complex concurrent systems,

More information

Java Memory Model. Jian Cao. Department of Electrical and Computer Engineering Rice University. Sep 22, 2016

Java Memory Model. Jian Cao. Department of Electrical and Computer Engineering Rice University. Sep 22, 2016 Java Memory Model Jian Cao Department of Electrical and Computer Engineering Rice University Sep 22, 2016 Content Introduction Java synchronization mechanism Double-checked locking Out-of-Thin-Air violation

More information

A separation logic for a promising semantics

A separation logic for a promising semantics A separation logic for a promising semantics Kasper Svendsen, Jean Pichon-Pharabod 1, Marko Doko 2, Ori Lahav 3, and Viktor Vafeiadis 2 1 University of Cambridge 2 MPI-SWS 3 Tel Aviv University Abstract.

More information

Reasoning About The Implementations Of Concurrency Abstractions On x86-tso. By Scott Owens, University of Cambridge.

Reasoning About The Implementations Of Concurrency Abstractions On x86-tso. By Scott Owens, University of Cambridge. Reasoning About The Implementations Of Concurrency Abstractions On x86-tso By Scott Owens, University of Cambridge. Plan Intro Data Races And Triangular Races Examples 2 sequential consistency The result

More information

Handout 3 Multiprocessor and thread level parallelism

Handout 3 Multiprocessor and thread level parallelism Handout 3 Multiprocessor and thread level parallelism Outline Review MP Motivation SISD v SIMD (SIMT) v MIMD Centralized vs Distributed Memory MESI and Directory Cache Coherency Synchronization and Relaxed

More information

Deterministic Parallel Programming

Deterministic Parallel Programming Deterministic Parallel Programming Concepts and Practices 04/2011 1 How hard is parallel programming What s the result of this program? What is data race? Should data races be allowed? Initially x = 0

More information

<atomic.h> weapons. Paolo Bonzini Red Hat, Inc. KVM Forum 2016

<atomic.h> weapons. Paolo Bonzini Red Hat, Inc. KVM Forum 2016 weapons Paolo Bonzini Red Hat, Inc. KVM Forum 2016 The real things Herb Sutter s talks atomic Weapons: The C++ Memory Model and Modern Hardware Lock-Free Programming (or, Juggling Razor Blades)

More information

GPU Concurrency: Weak Behaviours and Programming Assumptions

GPU Concurrency: Weak Behaviours and Programming Assumptions GPU Concurrency: Weak Behaviours and Programming Assumptions Jyh-Jing Hwang, Yiren(Max) Lu 03/02/2017 Outline 1. Introduction 2. Weak behaviors examples 3. Test methodology 4. Proposed memory model 5.

More information

SELECTED TOPICS IN COHERENCE AND CONSISTENCY

SELECTED TOPICS IN COHERENCE AND CONSISTENCY SELECTED TOPICS IN COHERENCE AND CONSISTENCY Michel Dubois Ming-Hsieh Department of Electrical Engineering University of Southern California Los Angeles, CA90089-2562 dubois@usc.edu INTRODUCTION IN CHIP

More information

Overhauling SC atomics in C11 and OpenCL

Overhauling SC atomics in C11 and OpenCL Overhauling SC atomics in C11 and OpenCL Mark Batty, Alastair F. Donaldson and John Wickerson INCITS/ISO/IEC 9899-2011[2012] (ISO/IEC 9899-2011, IDT) Provisional Specification Information technology Programming

More information

CSE502: Computer Architecture CSE 502: Computer Architecture

CSE502: Computer Architecture CSE 502: Computer Architecture CSE 502: Computer Architecture Shared-Memory Multi-Processors Shared-Memory Multiprocessors Multiple threads use shared memory (address space) SysV Shared Memory or Threads in software Communication implicit

More information

Announcements. ECE4750/CS4420 Computer Architecture L17: Memory Model. Edward Suh Computer Systems Laboratory

Announcements. ECE4750/CS4420 Computer Architecture L17: Memory Model. Edward Suh Computer Systems Laboratory ECE4750/CS4420 Computer Architecture L17: Memory Model Edward Suh Computer Systems Laboratory suh@csl.cornell.edu Announcements HW4 / Lab4 1 Overview Symmetric Multi-Processors (SMPs) MIMD processing cores

More information

Proving liveness. Alexey Gotsman IMDEA Software Institute

Proving liveness. Alexey Gotsman IMDEA Software Institute Proving liveness Alexey Gotsman IMDEA Software Institute Safety properties Ensure bad things don t happen: - the program will not commit a memory safety fault - it will not release a lock it does not hold

More information

Lecture 12. Lecture 12: The IO Model & External Sorting

Lecture 12. Lecture 12: The IO Model & External Sorting Lecture 12 Lecture 12: The IO Model & External Sorting Announcements Announcements 1. Thank you for the great feedback (post coming soon)! 2. Educational goals: 1. Tech changes, principles change more

More information

Shared Memory Consistency Models: A Tutorial

Shared Memory Consistency Models: A Tutorial Shared Memory Consistency Models: A Tutorial By Sarita Adve, Kourosh Gharachorloo WRL Research Report, 1995 Presentation: Vince Schuster Contents Overview Uniprocessor Review Sequential Consistency Relaxed

More information

Relaxed Memory-Consistency Models

Relaxed Memory-Consistency Models Relaxed Memory-Consistency Models Review. Why are relaxed memory-consistency models needed? How do relaxed MC models require programs to be changed? The safety net between operations whose order needs

More information

Motivations. Shared Memory Consistency Models. Optimizations for Performance. Memory Consistency

Motivations. Shared Memory Consistency Models. Optimizations for Performance. Memory Consistency Shared Memory Consistency Models Authors : Sarita.V.Adve and Kourosh Gharachorloo Presented by Arrvindh Shriraman Motivations Programmer is required to reason about consistency to ensure data race conditions

More information

Overhauling SC atomics in C11 and OpenCL

Overhauling SC atomics in C11 and OpenCL Overhauling SC atomics in C11 and OpenCL Abstract Despite the conceptual simplicity of sequential consistency (SC), the semantics of SC atomic operations and fences in the C11 and OpenCL memory models

More information

TriCheck: Memory Model Verification at the Trisection of Software, Hardware, and ISA

TriCheck: Memory Model Verification at the Trisection of Software, Hardware, and ISA TriCheck: Memory Model Verification at the Trisection of Software, Hardware, and ISA Caroline Trippel Yatin A. Manerkar Daniel Lustig* Michael Pellauer* Margaret Martonosi Princeton University *NVIDIA

More information

Transaction Management and Concurrency Control. Chapter 16, 17

Transaction Management and Concurrency Control. Chapter 16, 17 Transaction Management and Concurrency Control Chapter 16, 17 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh

More information

TriCheck: Memory Model Verification at the Trisection of Software, Hardware, and ISA

TriCheck: Memory Model Verification at the Trisection of Software, Hardware, and ISA TriCheck: Memory Model Verification at the Trisection of Software, Hardware, and ISA Caroline Trippel Yatin A. Manerkar Daniel Lustig* Michael Pellauer* Margaret Martonosi Princeton University {ctrippel,manerkar,mrm}@princeton.edu

More information

Stability in Weak Memory Models

Stability in Weak Memory Models Stability in Weak Memory Models Jade Alglave 1,2 and Luc Maranget 2 1 Oxford University 2 INRIA Abstract. Concurrent programs running on weak memory models exhibit relaxed behaviours, making them hard

More information

Overhauling SC Atomics in C11 and OpenCL

Overhauling SC Atomics in C11 and OpenCL Overhauling SC Atomics in C11 and OpenCL Mark Batty University of Kent, UK m.j.batty@kent.ac.uk Alastair F. Donaldson Imperial College London, UK alastair.donaldson@imperial.ac.uk John Wickerson Imperial

More information

Concurrency Control. Chapter 17. Comp 521 Files and Databases Spring

Concurrency Control. Chapter 17. Comp 521 Files and Databases Spring Concurrency Control Chapter 17 Comp 521 Files and Databases Spring 2010 1 Conflict Serializable Schedules Recall conflicts (WW, RW, WW) were the cause of sequential inconsistency Two schedules are conflict

More information

Analyzing Snapshot Isolation

Analyzing Snapshot Isolation Analyzing Snapshot Isolation Andrea Cerone Alexey Gotsman IMDEA Software Institute PODC 2016 presented by Dima Kuznetsov Andrea Cerone, Alexey Gotsman (IMDEA) Analyzing Snapshot Isolation PODC 2016 1 /

More information

Goal of Concurrency Control. Concurrency Control. Example. Solution 1. Solution 2. Solution 3

Goal of Concurrency Control. Concurrency Control. Example. Solution 1. Solution 2. Solution 3 Goal of Concurrency Control Concurrency Control Transactions should be executed so that it is as though they executed in some serial order Also called Isolation or Serializability Weaker variants also

More information

Concurrency Control Serializable Schedules and Locking Protocols

Concurrency Control Serializable Schedules and Locking Protocols .. Spring 2008 CSC 468: DBMS Implementation Alexander Dekhtyar.. Concurrency Control Serializable Schedules and Locking Protocols Serializability Revisited Goals of DBMS: 1. Ensure consistency of database

More information

A Concurrency Semantics for Relaxed Atomics that Permits Optimisation and Avoids Thin-Air Executions

A Concurrency Semantics for Relaxed Atomics that Permits Optimisation and Avoids Thin-Air Executions A Concurrency Semantics for Relaxed Atomics that Permits Optimisation and Avoids Thin-Air Executions Jean Pichon-Pharabod Peter Sewell University of Cambridge, United Kingdom first.last@cl.cam.ac.uk Abstract

More information

Weak memory models. Mai Thuong Tran. PMA Group, University of Oslo, Norway. 31 Oct. 2014

Weak memory models. Mai Thuong Tran. PMA Group, University of Oslo, Norway. 31 Oct. 2014 Weak memory models Mai Thuong Tran PMA Group, University of Oslo, Norway 31 Oct. 2014 Overview 1 Introduction Hardware architectures Compiler optimizations Sequential consistency 2 Weak memory models TSO

More information

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101 CSC 261/461 Database Systems Lecture 21 and 22 Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101 Announcements Project 3 (MongoDB): Due on: 04/12 Work on Term Project and Project 1 The last (mini)

More information

New Programming Abstractions for Concurrency in GCC 4.7. Torvald Riegel Red Hat 12/04/05

New Programming Abstractions for Concurrency in GCC 4.7. Torvald Riegel Red Hat 12/04/05 New Programming Abstractions for Concurrency in GCC 4.7 Red Hat 12/04/05 1 Concurrency and atomicity C++11 atomic types Transactional Memory Provide atomicity for concurrent accesses by different threads

More information

Compositional Verification of Compiler Optimisations on Relaxed Memory

Compositional Verification of Compiler Optimisations on Relaxed Memory Compositional Verification of Compiler Optimisations on Relaxed Memory Mike Dodds 1, Mark Batty 2, and Alexey Gotsman 3 1 Galois Inc. 2 University of Kent 3 IMDEA Software Institute Abstract. A valid compiler

More information

THÈSE DE DOCTORAT de l Université de recherche Paris Sciences Lettres PSL Research University

THÈSE DE DOCTORAT de l Université de recherche Paris Sciences Lettres PSL Research University THÈSE DE DOCTORAT de l Université de recherche Paris Sciences Lettres PSL Research University Préparée à l École normale supérieure Compiler Optimisations and Relaxed Memory Consistency Models ED 386 sciences

More information

Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it

Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it Comn Compiler Optimisations are Invalid in the C11 Mery Model and what we can do about it Viktor Vafeiadis MPI-SWS Thibaut Balabonski INRIA Soham Chakraborty MPI-SWS Robin Morisset INRIA Francesco Zappa

More information

The Java Memory Model

The Java Memory Model The Java Memory Model The meaning of concurrency in Java Bartosz Milewski Plan of the talk Motivating example Sequential consistency Data races The DRF guarantee Causality Out-of-thin-air guarantee Implementation

More information

C++ Concurrency - Formalised

C++ Concurrency - Formalised C++ Concurrency - Formalised Salomon Sickert Technische Universität München 26 th April 2013 Mutex Algorithms At most one thread is in the critical section at any time. 2 / 35 Dekker s Mutex Algorithm

More information

arxiv: v2 [cs.pl] 9 Jul 2016

arxiv: v2 [cs.pl] 9 Jul 2016 Operational Aspects of C/C++ Concurrency July 12, 2016 Anton Podkopaev Saint Petersburg State University and JetBrains Inc., Russia a.podkopaev@2009.spbu.ru Ilya Sergey University College London, UK i.sergey@ucl.ac.uk

More information

CS510 Advanced Topics in Concurrency. Jonathan Walpole

CS510 Advanced Topics in Concurrency. Jonathan Walpole CS510 Advanced Topics in Concurrency Jonathan Walpole Threads Cannot Be Implemented as a Library Reasoning About Programs What are the valid outcomes for this program? Is it valid for both r1 and r2 to

More information

Concurrency Control. Chapter 17. Comp 521 Files and Databases Fall

Concurrency Control. Chapter 17. Comp 521 Files and Databases Fall Concurrency Control Chapter 17 Comp 521 Files and Databases Fall 2012 1 Conflict Serializable Schedules Recall conflicts (WR, RW, WW) were the cause of sequential inconsistency Two schedules are conflict

More information

CMSC Computer Architecture Lecture 15: Memory Consistency and Synchronization. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 15: Memory Consistency and Synchronization. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 15: Memory Consistency and Synchronization Prof. Yanjing Li University of Chicago Administrative Stuff! Lab 5 (multi-core) " Basic requirements: out later today

More information

Implementing the C11 memory model for ARM processors. Will Deacon February 2015

Implementing the C11 memory model for ARM processors. Will Deacon February 2015 1 Implementing the C11 memory model for ARM processors Will Deacon February 2015 Introduction 2 ARM ships intellectual property, specialising in RISC microprocessors Over 50 billion

More information

Using Weakly Ordered C++ Atomics Correctly. Hans-J. Boehm

Using Weakly Ordered C++ Atomics Correctly. Hans-J. Boehm Using Weakly Ordered C++ Atomics Correctly Hans-J. Boehm 1 Why atomics? Programs usually ensure that memory locations cannot be accessed by one thread while being written by another. No data races. Typically

More information

NOW Handout Page 1. Memory Consistency Model. Background for Debate on Memory Consistency Models. Multiprogrammed Uniprocessor Mem.

NOW Handout Page 1. Memory Consistency Model. Background for Debate on Memory Consistency Models. Multiprogrammed Uniprocessor Mem. Memory Consistency Model Background for Debate on Memory Consistency Models CS 258, Spring 99 David E. Culler Computer Science Division U.C. Berkeley for a SAS specifies constraints on the order in which

More information

Self Stabilization. CS553 Distributed Algorithms Prof. Ajay Kshemkalyani. by Islam Ismailov & Mohamed M. Ali

Self Stabilization. CS553 Distributed Algorithms Prof. Ajay Kshemkalyani. by Islam Ismailov & Mohamed M. Ali Self Stabilization CS553 Distributed Algorithms Prof. Ajay Kshemkalyani by Islam Ismailov & Mohamed M. Ali Introduction There is a possibility for a distributed system to go into an illegitimate state,

More information

The Cache-Coherence Problem

The Cache-Coherence Problem The -Coherence Problem Lecture 12 (Chapter 6) 1 Outline Bus-based multiprocessors The cache-coherence problem Peterson s algorithm Coherence vs. consistency Shared vs. Distributed Memory What is the difference

More information

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts Toshiyuki Maeda and Akinori Yonezawa University of Tokyo Quiz [Environment] CPU: Intel Xeon X5570 (2.93GHz)

More information

Lectures 8 & 9. Lectures 7 & 8: Transactions

Lectures 8 & 9. Lectures 7 & 8: Transactions Lectures 8 & 9 Lectures 7 & 8: Transactions Lectures 7 & 8 Goals for this pair of lectures Transactions are a programming abstraction that enables the DBMS to handle recoveryand concurrency for users.

More information

TRANSACTION MANAGEMENT

TRANSACTION MANAGEMENT TRANSACTION MANAGEMENT CS 564- Spring 2018 ACKs: Jeff Naughton, Jignesh Patel, AnHai Doan WHAT IS THIS LECTURE ABOUT? Transaction (TXN) management ACID properties atomicity consistency isolation durability

More information

Relaxed Separation Logic: A Program Logic for C11 Concurrency

Relaxed Separation Logic: A Program Logic for C11 Concurrency Relaxed Separation Logic: A rogram Logic for C11 Concurrency Viktor Vafeiadis Max lanck Institute for Software Systems (MI-SWS) viktor@mpi-sws.org Chinmay Narayan Indian Institute of Technology, Delhi

More information

Understanding POWER multiprocessors

Understanding POWER multiprocessors Understanding POWER multiprocessors Susmit Sarkar 1 Peter Sewell 1 Jade Alglave 2,3 Luc Maranget 3 Derek Williams 4 1 University of Cambridge 2 Oxford University 3 INRIA 4 IBM June 2011 Programming shared-memory

More information

New Programming Abstractions for Concurrency. Torvald Riegel Red Hat 12/04/05

New Programming Abstractions for Concurrency. Torvald Riegel Red Hat 12/04/05 New Programming Abstractions for Concurrency Red Hat 12/04/05 1 Concurrency and atomicity C++11 atomic types Transactional Memory Provide atomicity for concurrent accesses by different threads Both based

More information

A Revisionist History of Denotational Semantics

A Revisionist History of Denotational Semantics A Revisionist History of Denotational Semantics Stephen Brookes Carnegie Mellon University Domains XIII July 2018 1 / 23 Denotational Semantics Compositionality Principle The meaning of a complex expression

More information

Pattern-based Synthesis of Synchronization for the C++ Memory Model

Pattern-based Synthesis of Synchronization for the C++ Memory Model Pattern-based Synthesis of Synchronization for the C++ Memory Model Yuri Meshman Technion Noam Rinetzky Tel Aviv University Eran Yahav Technion Abstract We address the problem of synthesizing efficient

More information

CS 252 Graduate Computer Architecture. Lecture 11: Multiprocessors-II

CS 252 Graduate Computer Architecture. Lecture 11: Multiprocessors-II CS 252 Graduate Computer Architecture Lecture 11: Multiprocessors-II Krste Asanovic Electrical Engineering and Computer Sciences University of California, Berkeley http://www.eecs.berkeley.edu/~krste http://inst.eecs.berkeley.edu/~cs252

More information

Coherence and Consistency

Coherence and Consistency Coherence and Consistency 30 The Meaning of Programs An ISA is a programming language To be useful, programs written in it must have meaning or semantics Any sequence of instructions must have a meaning.

More information

An operational semantics for C/C++11 concurrency

An operational semantics for C/C++11 concurrency Draft An operational semantics for C/C++11 concurrency Kyndylan Nienhuis Kayvan Memarian Peter Sewell University of Cambridge first.last@cl.cam.ac.uk Abstract The C/C++11 concurrency model balances two

More information

Symmetric Multiprocessors: Synchronization and Sequential Consistency

Symmetric Multiprocessors: Synchronization and Sequential Consistency Constructive Computer Architecture Symmetric Multiprocessors: Synchronization and Sequential Consistency Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November

More information

Review of last lecture. Peer Quiz. DPHPC Overview. Goals of this lecture. Lock-based queue

Review of last lecture. Peer Quiz. DPHPC Overview. Goals of this lecture. Lock-based queue Review of last lecture Design of Parallel and High-Performance Computing Fall 2016 Lecture: Linearizability Motivational video: https://www.youtube.com/watch?v=qx2driqxnbs Instructor: Torsten Hoefler &

More information

GPS: Navigating Weak Memory with Ghosts, Protocols, and Separation

GPS: Navigating Weak Memory with Ghosts, Protocols, and Separation * Evaluated * OOPSLA * Artifact * AEC GPS: Navigating Weak Memory with Ghosts, Protocols, and Separation Aaron Turon Viktor Vafeiadis Derek Dreyer Max Planck Institute for Software Systems (MPI-SWS) turon,viktor,dreyer@mpi-sws.org

More information

Introduction. Coherency vs Consistency. Lec-11. Multi-Threading Concepts: Coherency, Consistency, and Synchronization

Introduction. Coherency vs Consistency. Lec-11. Multi-Threading Concepts: Coherency, Consistency, and Synchronization Lec-11 Multi-Threading Concepts: Coherency, Consistency, and Synchronization Coherency vs Consistency Memory coherency and consistency are major concerns in the design of shared-memory systems. Consistency

More information

Multicore Programming Java Memory Model

Multicore Programming Java Memory Model p. 1 Multicore Programming Java Memory Model Peter Sewell Jaroslav Ševčík Tim Harris University of Cambridge MSR with thanks to Francesco Zappa Nardelli, Susmit Sarkar, Tom Ridge, Scott Owens, Magnus O.

More information

Lecture 21. Lecture 21: Concurrency & Locking

Lecture 21. Lecture 21: Concurrency & Locking Lecture 21 Lecture 21: Concurrency & Locking Lecture 21 Today s Lecture 1. Concurrency, scheduling & anomalies 2. Locking: 2PL, conflict serializability, deadlock detection 2 Lecture 21 > Section 1 1.

More information

High-level languages

High-level languages High-level languages High-level languages are not immune to these problems. Actually, the situation is even worse: the source language typically operates over mixed-size values (multi-word and bitfield);

More information

Parallel Computer Architecture Spring Memory Consistency. Nikos Bellas

Parallel Computer Architecture Spring Memory Consistency. Nikos Bellas Parallel Computer Architecture Spring 2018 Memory Consistency Nikos Bellas Computer and Communications Engineering Department University of Thessaly Parallel Computer Architecture 1 Coherence vs Consistency

More information

Lecture 1: Conjunctive Queries

Lecture 1: Conjunctive Queries CS 784: Foundations of Data Management Spring 2017 Instructor: Paris Koutris Lecture 1: Conjunctive Queries A database schema R is a set of relations: we will typically use the symbols R, S, T,... to denote

More information

From IMP to Java. Andreas Lochbihler. parts based on work by Gerwin Klein and Tobias Nipkow ETH Zurich

From IMP to Java. Andreas Lochbihler. parts based on work by Gerwin Klein and Tobias Nipkow ETH Zurich From IMP to Java Andreas Lochbihler ETH Zurich parts based on work by Gerwin Klein and Tobias Nipkow 2015-07-14 1 Subtyping 2 Objects and Inheritance 3 Multithreading 1 Subtyping 2 Objects and Inheritance

More information

arxiv: v2 [cs.pl] 30 Aug 2016

arxiv: v2 [cs.pl] 30 Aug 2016 Syntax and semantics of the weak consistency model specification language cat arxiv:1608.07531v2 [cs.pl] 30 Aug 2016 Jade Alglave Microsoft Research Cambridge University College London jaalgl av@ mic rosoft.com,

More information

Page 1. Cache Coherence

Page 1. Cache Coherence Page 1 Cache Coherence 1 Page 2 Memory Consistency in SMPs CPU-1 CPU-2 A 100 cache-1 A 100 cache-2 CPU-Memory bus A 100 memory Suppose CPU-1 updates A to 200. write-back: memory and cache-2 have stale

More information

Sequential Consistency & TSO. Subtitle

Sequential Consistency & TSO. Subtitle Sequential Consistency & TSO Subtitle Core C1 Core C2 data = 0, 1lag SET S1: store data = NEW S2: store 1lag = SET L1: load r1 = 1lag B1: if (r1 SET) goto L1 L2: load r2 = data; Will r2 always be set to

More information

A Denotational Semantics for Weak Memory Concurrency

A Denotational Semantics for Weak Memory Concurrency A Denotational Semantics for Weak Memory Concurrency Stephen Brookes Carnegie Mellon University Department of Computer Science Midlands Graduate School April 2016 Work supported by NSF 1 / 120 Motivation

More information

Memory Consistency Models

Memory Consistency Models Calcolatori Elettronici e Sistemi Operativi Memory Consistency Models Sources of out-of-order memory accesses... Compiler optimizations Store buffers FIFOs for uncommitted writes Invalidate queues (for

More information

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636) What are Transactions? Transaction Management: Introduction (Chap. 16) CS634 Class 14, Mar. 23, 2016 So far, we looked at individual queries; in practice, a task consists of a sequence of actions E.g.,

More information

Memory Consistency Models

Memory Consistency Models Memory Consistency Models Contents of Lecture 3 The need for memory consistency models The uniprocessor model Sequential consistency Relaxed memory models Weak ordering Release consistency Jonas Skeppstedt

More information

Programming Language Memory Models: What do Shared Variables Mean?

Programming Language Memory Models: What do Shared Variables Mean? Programming Language Memory Models: What do Shared Variables Mean? Hans-J. Boehm 10/25/2010 1 Disclaimers: This is an overview talk. Much of this work was done by others or jointly. I m relying particularly

More information

Beyond Sequential Consistency: Relaxed Memory Models

Beyond Sequential Consistency: Relaxed Memory Models 1 Beyond Sequential Consistency: Relaxed Memory Models Computer Science and Artificial Intelligence Lab M.I.T. Based on the material prepared by and Krste Asanovic 2 Beyond Sequential Consistency: Relaxed

More information

Transaction Management: Introduction (Chap. 16)

Transaction Management: Introduction (Chap. 16) Transaction Management: Introduction (Chap. 16) CS634 Class 14 Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke What are Transactions? So far, we looked at individual queries;

More information

TSO-CC: Consistency-directed Coherence for TSO. Vijay Nagarajan

TSO-CC: Consistency-directed Coherence for TSO. Vijay Nagarajan TSO-CC: Consistency-directed Coherence for TSO Vijay Nagarajan 1 People Marco Elver (Edinburgh) Bharghava Rajaram (Edinburgh) Changhui Lin (Samsung) Rajiv Gupta (UCR) Susmit Sarkar (St Andrews) 2 Multicores

More information