Clarifying and compiling C/C++ concurrency
Open Access
- 25 January 2012
- conference paper
- Published by Association for Computing Machinery (ACM)
- p. 509-520
Abstract
The upcoming C and C++ revised standards add concurrency to the languages, for the first time, in the form of a subtle *relaxed memory model* (the *C++11 model*). This aims to permit compiler optimisation and to accommodate the differing relaxed-memory behaviours of mainstream multiprocessors, combining simple semantics for most code with high-performance *low-level atomics* for concurrency libraries. In this paper, we first establish two simpler but provably equivalent models for C++11, one for the full language and another for the subset without consume operations. Subsetting further to the fragment without low-level atomics, we identify a subtlety arising from atomic initialisation and prove that, under an additional condition, the model is equivalent to sequential consistency for race-free programs. We then prove our main result, the correctness of two proposed compilation schemes for the C++11 load and store concurrency primitives to Power assembly, having noted that an earlier proposal was flawed. (The main ideas apply also to ARM, which has a similar relaxed memory architecture.) This should inform the ongoing development of production compilers for C++11 and C1x, clarifies what properties of the machine architecture are required, and builds confidence in the C++11 and Power semantics.Keywords
This publication has 16 references indexed in Scilit:
- Nitpicking c++ concurrency2011
- x86-TSOCommunications of the ACM, 2010
- Fences in Weak Memory Models2010
- Verifying Local Transformations on Relaxed Memory Models2010
- Verifying a Compiler for Java Threads2010
- A Formally Verified Compiler Back-endJournal of Automated Reasoning, 2009
- Foundations of the C++ concurrency memory model2008
- Automatic fence insertion for shared memory multiprocessing2003
- Weak ordering---a new definition1990
- Efficient and correct execution of parallel programs that share memoryACM Transactions on Programming Languages and Systems, 1988