skip to main content
research-article

Mathematizing C++ concurrency

Authors Info & Claims
Published:26 January 2011Publication History
Skip Abstract Section

Abstract

Shared-memory concurrency in C and C++ is pervasive in systems programming, but has long been poorly defined. This motivated an ongoing shared effort by the standards committees to specify concurrent behaviour in the next versions of both languages. They aim to provide strong guarantees for race-free programs, together with new (but subtle) relaxed-memory atomic primitives for high-performance concurrent code. However, the current draft standards, while the result of careful deliberation, are not yet clear and rigorous definitions, and harbour substantial problems in their details.

In this paper we establish a mathematical (yet readable) semantics for C++ concurrency. We aim to capture the intent of the current (`Final Committee') Draft as closely as possible, but discuss changes that fix many of its problems. We prove that a proposed x86 implementation of the concurrency primitives is correct with respect to the x86-TSO model, and describe our Cppmem tool for exploring the semantics of examples, using code generated from our Isabelle/HOL definitions.

Having already motivated changes to the draft standard, this work will aid discussion of any further changes, provide a correctness condition for compilers, and give a much-needed basis for analysis and verification of concurrent C and C++ programs.

Skip Supplemental Material Section

Supplemental Material

7-mpeg-4.mp4

mp4

368.2 MB

References

  1. S. V. Adve and H.-J. Boehm. Memory models: A case for rethinking parallel languages and hardware. C. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. J. Alglave, L. Maranget, S. Sarkar, and P. Sewell. Fences in weak memory models. In Proc. CAV, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. ARM. ARM Architecture Reference Manual (ARMv7-A and ARMv7-R edition). April 2008.Google ScholarGoogle Scholar
  4. H.-J. Boehm and S.V. Adve. Foundations of the C++ concurrency memory model. In Proc. PLDI, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. P. Becker, editor. Programming Languages --- C++. Final Committee Draft. 2010. ISO/IEC JTC1 SC22 WG21 N3092.Google ScholarGoogle Scholar
  6. Jasmin Christian Blanchette and Tobias Nipkow. Nitpick: A counterexample generator for higher-order logic based on a relational model finder. In Proc. ITP, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. www.cl.cam.ac.uk/users/pes20/cpp.Google ScholarGoogle Scholar
  8. JTC1/SC22/WG14 --- C. http://www.open-std.org/jtc1/sc22/wg14/.Google ScholarGoogle Scholar
  9. P. Cenciarelli, A. Knapp, and E. Sibilio. The Java memory model: Operationally, denotationally, axiomatically. In Proc. ESOP, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. E. R. Gansner and S. C. North. An open graph visualization system and its applications to software engineering. Softw. Pract. Exper., 30(11):1203--1233, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Florian Haftmann. Code Generation from Specifications in Higher-Order Logic. PhD thesis, TU München, 2009.Google ScholarGoogle Scholar
  12. The HOL 4 system. http://hol.sourceforge.net/.Google ScholarGoogle Scholar
  13. Intel. A formal specification of Intel Itanium processor family memory ordering. http://www.intel.com/design/itanium/downloads/251429.htm, October 2002.Google ScholarGoogle Scholar
  14. Isabelle 2009-2. http://isabelle.in.tum.de/.Google ScholarGoogle Scholar
  15. L. Lamport. How to make a multiprocessor computer that correctly executes multiprocess programs. IEEE Trans. Comput., C-28(9):690--691, 1979. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. J. Manson,W. Pugh, and S.V. Adve. The Java memory model. In Proc. POPL, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. P. E. McKenney and R. Silvera. Example POWER implementation for C/C++ memory model. http://www.rdrop.com/users/paulmck/scalability/paper/N2745r.2010.02.19a.html, 2010.Google ScholarGoogle Scholar
  18. P. E. McKenney and J. Walpole. What is RCU, fundamentally? Linux Weekly News, http://lwn.net/Articles/262464/.Google ScholarGoogle Scholar
  19. George C. Necula, Scott McPeak, Shree Prakash Rahul, and Westley Weimer. Cil: Intermediate language and tools for analysis and transformation of c programs. In Proc. CC, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. M. Norrish. A formal semantics for C++. Technical report, NICTA, 2008.Google ScholarGoogle Scholar
  21. S. Owens, S. Sarkar, and P. Sewell. A better x86 memory model: x86-TSO. In Proc. TPHOLs, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Owens. Reasoning about the implementation of concurrency abstractions on x86-TSO. In Proc. ECOOP, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Power ISA Version 2.06. IBM, 2009.Google ScholarGoogle Scholar
  24. W. Pugh. The Java memory model is fatally flawed. Concurrency - Practice and Experience, 12(6), 2000.Google ScholarGoogle Scholar
  25. J. Ševçík and D. Aspinall. On validity of program transformations in the Java memory model. In ECOOP, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. The SPARC architecture manual, v. 9. http://dev elopers.sun.com/solaris/articles/sparcv9.pdf. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. P. Sewell, S. Sarkar, S. Owens, F. Zappa Nardelli, and M. O. Myreen. x86-TSO: A rigorous and usable programmer's model for x86 multiprocessors. C. ACM, 53(7):89--97, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. S. Sarkar, P. Sewell, F. Zappa Nardelli, S. Owens, T. Ridge, T. Braibant, M. Myreen, and J. Alglave. The semantics of x86-CC multiprocessor machine code. In Proc. POPL, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. A. Terekhov. Brief tentative example x86 implementation for C/C++ memory model. cpp-threads mailing list, http://www.decadent.org.uk/pipermail/cpp-threads/2008-December/001933.html, Dec. 2008.Google ScholarGoogle Scholar
  30. E. Torlak and D. Jackson. Kodkod: a relational model finder. In Proc. TACAS, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. E. Torlak, M. Vaziri, and J. Dolby. MemSAT: checking axiomatic specifications of memory models. In PLDI, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Y. Yang, G. Gopalakrishnan, G. Lindstrom, and K. Slind. Nemos: A framework for axiomatic and executable specifications of memory consistency models. In IPDPS, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  33. M. Zalewski. Generic Programming with Concepts. PhD thesis, Chalmers University, November 2008.Google ScholarGoogle Scholar

Index Terms

  1. Mathematizing C++ concurrency

            Recommendations

            Reviews

            Wolfgang Schreiner

            Integrating multi-threading into a programming language such as C++ is an error-prone task: the intuitive expectation of a "sequentially consistent" program that behaves as if concurrent memory reads and writes were put into some linear order cannot be satisfied, because modern compilers and processors need the flexibility to reorder instructions or delay memory updates. To support high-performance concurrent algorithms, the forthcoming C++0x standard defines atomic synchronization primitives with a weaker semantics, which is difficult to understand. Establishing the correctness of a compiler is thus a challenging task. This paper addresses the problem by providing a formal model of C++0x concurrency. A program is translated into the set of its possible executions, which are defined by mathematical relations among the program's memory actions and must satisfy certain correctness constraints such as freedom of data races. The authors give a detailed explanation of the formalization and present various examples that illustrate the semantics of typical programming patterns. The formalization is expressed in the proving environment Isabelle/HOL and automatically translated into the core of the CPPMEM tool, which produces from a C++0x program a visualization of its possible executions. Throughout the formalization process, the authors collaborated with the C++ standardization committee to clarify various subtle features, inconsistencies, and errors in the proposed standard and to prove the correctness of a proposed x86 implementation of the concurrency primitives. The presented formalization can thus provide a much-needed reference for the implementation of the standard and for the analysis of concurrent C++ programs. Online Computing Reviews Service

            Access critical reviews of Computing literature here

            Become a reviewer for Computing Reviews.

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM SIGPLAN Notices
              ACM SIGPLAN Notices  Volume 46, Issue 1
              POPL '11
              January 2011
              624 pages
              ISSN:0362-1340
              EISSN:1558-1160
              DOI:10.1145/1925844
              Issue’s Table of Contents
              • cover image ACM Conferences
                POPL '11: Proceedings of the 38th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
                January 2011
                652 pages
                ISBN:9781450304900
                DOI:10.1145/1926385

              Copyright © 2011 ACM

              Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 26 January 2011

              Check for updates

              Qualifiers

              • research-article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader