Nothing Special   »   [go: up one dir, main page]

skip to main content
research-article

Dynamic race detection for C++11

Published: 01 January 2017 Publication History

Abstract

The intricate rules for memory ordering and synchronisation associated with the C/C++11 memory model mean that data races can be difficult to eliminate from concurrent programs. Dynamic data race analysis can pinpoint races in large and complex applications, but the state-of-the-art ThreadSanitizer (tsan) tool for C/C++ considers only sequentially consistent program executions, and does not correctly model synchronisation between C/C++11 atomic operations. We present a scalable dynamic data race analysis for C/C++11 that correctly captures C/C++11 synchronisation, and uses instrumentation to support exploration of a class of non sequentially consistent executions. We concisely define the memory model fragment captured by our instrumentation via a restricted axiomatic semantics, and show that the axiomatic semantics permits exactly those executions explored by our instrumentation. We have implemented our analysis in tsan, and evaluate its effectiveness on benchmark programs, enabling a comparison with the CDSChecker tool, and on two large and highly concurrent applications: the Firefox and Chromium web browsers. Our results show that our method can detect races that are beyond the scope of the original tsan tool, and that the overhead associated with applying our enhanced instrumentation to large applications is tolerable.

References

[1]
S. Adve. Data races are evil with no exceptions: Technical perspective. Commun. ACM, 53:84–84, 2010.
[2]
J. Alglave, D. Kroening, V. Nimal, and M. Tautschnig. Software verification for weak memory via program transformation. In ESOP, pages 512–532, 2013.
[3]
J. Alglave, L. Maranget, and M. Tautschnig. Herding cats: Modelling, simulation, testing, and data mining for weak memory. ACM Trans. Program. Lang. Syst., 36(2):7:1–7:74, 2014.
[4]
J. Alglave, M. Batty, A. F. Donaldson, G. Gopalakrishnan, J. Ketema, D. Poetzl, T. Sorensen, and J. Wickerson. GPU concurrency: Weak behaviours and programming assumptions. In ASPLOS, pages 577– 591, 2015.
[5]
M. Batty, S. Owens, S. Sarkar, P. Sewell, and T. Weber. Mathematizing C++ concurrency: The post-Rapperswil model. Technical Report N3132=10-0122, JTC1/SC22/WG21 – The C++ Standards Committee, 2010.
[6]
M. Batty, S. Owens, S. Sarkar, P. Sewell, and T. Weber. Mathematizing C++ concurrency. In POPL, pages 55–66, 2011.
[7]
M. Batty, K. Memarian, S. Owens, S. Sarkar, and P. Sewell. Clarifying and compiling C/C++ concurrency: from C++ 11 to POWER. In POPL, pages 509–520, 2012.
[8]
M. Batty, A. F. Donaldson, and J. Wickerson. Overhauling SC atomics in C11 and OpenCL. In POPL, pages 634–648, 2016.
[9]
J. C. Blanchette, T. Weber, M. Batty, S. Owens, and S. Sarkar. Nitpicking C++ concurrency. In PPDP, pages 113–124, 2011.
[10]
M. Cao, J. Roemer, A. Sengupta, and M. D. Bond. Prescient memory: exposing weak memory model behavior by looking into the future. In ISMM, pages 99–110, 2016.
[11]
S. Chakraborty and V. Vafeiadis. Validating optimizations of concurrent C/C++ programs. In CGO, pages 216–226, 2016.
[12]
M. Doko and V. Vafeiadis. A program logic for C11 memory fences. In VMCAI, pages 413–430, 2016.
[13]
T. Elmas, S. Qadeer, and S. Tasiran. Goldilocks: a race-aware Java runtime. Commun. ACM, 53(11):85–92, 2010.
[14]
D. R. Engler and K. Ashcraft. RacerX: effective, static detection of race conditions and deadlocks. In SOSP, pages 237–252, 2003.
[15]
C. Flanagan and S. N. Freund. FastTrack: efficient and precise dynamic race detection. In PLDI, pages 121–133, 2009.
[16]
C. Flanagan and S. N. Freund. Adversarial memory for detecting destructive races. In PLDI, pages 244–254, 2010.
[17]
C. Flanagan and P. Godefroid. Dynamic partial-order reduction for model checking software. In POPL, pages 110–121, 2005.
[18]
Google. KernelThreadSanitizer, a fast data race detector for the Linux kernel, visited November 2016.
[19]
https://github.com/google/ ktsan.
[20]
ISO/IEC. Programming languages – C. International standard 9899:2011, 2011.
[21]
ISO/IEC. Programming languages – C++. International standard 14882:2011, 2011.
[22]
A. Itzkovitz, A. Schuster, and O. Zeev-Ben-Mordehai. Toward integration of data race detection in DSM systems. J. Parallel Distrib. Comput., 59(2):180–203, 1999.
[23]
H. Jin, T. Yavuz-Kahveci, and B. A. Sanders. Java memory modelaware model checking. In TACAS, pages 220–236, 2012.
[24]
R. Krebbers and F. Wiedijk. A typed C11 semantics for interactive theorem proving. In CPP, pages 15–27, 2015.
[25]
O. Lahav, N. Giannarakis, and V. Vafeiadis. Taming release-acquire consistency. In POPL, pages 649–662, 2016.
[26]
L. Lamport. Time, clocks, and the ordering of events in a distributed system. Commun. ACM, 21(7):558–565, 1978.
[27]
C. Lidbury and A. F. Donaldson. Companion webiste for reproducibility of experiments, 2017. http://multicore.doc.ic.ac. uk/projects/tsan11/.
[28]
C. Lidbury and A. F. Donaldson. Dynamic race detection for C++11: Extended version, 2017.
[29]
https://www.doc.ic.ac.uk/ ~afd/homepages/papers/pdfs/2017/POPLExtended.pdf.
[30]
F. Mattern. Virtual time and global states of distributed systems. In Proc. Workshop on Parallel and Distributed Algorithms, pages 215– 226, 1988.
[31]
R. Morisset, P. Pawan, and F. Zappa Nardelli. Compiler testing via a theory of sound optimisations in the C11/C++11 memory model. In PLDI, pages 187–196, 2013.
[32]
K. Nienhuis, K. Memarian, and P. Sewell. An operational semantics for C/C++11 concurrency. In OOPSLA, pages 111–128, 2016.
[33]
B. Norris and B. Demsky. CDSchecker: checking concurrent data structures written with C/C++ atomics. In OOPSLA, pages 131–150, 2013.
[34]
B. Norris and B. Demsky. A practical approach for model checking C/C++11 code. ACM Trans. Program. Lang. Syst., 38(3):10, 2016.
[35]
Oracle Corporation. Analyzing program performance with Sun Work-Shop, Chapter 5: Lock analysis tool. http://docs.oracle.com/ cd/E19059-01/wrkshp50/805-4947/6j4m8jrnd/index.html, 2010.
[36]
J. Pichon-Pharabod and P. Sewell. A concurrency semantics for relaxed atomics that permits optimisation and avoids thin-air executions. In POPL, pages 622–633, 2016.
[37]
A. Podkopaev, I. Sergey, and A. Nanevski. Operational aspects of C/C++ concurrency. CoRR, abs/1606.01400, 2016.
[38]
D. Poetzl and D. Kroening. Formalizing and checking thread refinement for data-race-free execution models. In TACAS, pages 515–530, 2016.
[39]
E. Pozniansky and A. Schuster. Efficient on-the-fly data race detection in multihreaded C++ programs. In PPoPP, pages 179–190, 2003.
[40]
E. Pozniansky and A. Schuster. Multirace: efficient on-the-fly data race detection in multithreaded C++ programs. Concurrency and Computation: Practice and Experience, 19(3):327–340, 2007.
[41]
P. Pratikakis, J. S. Foster, and M. Hicks. LOCKSMITH: contextsensitive correlation analysis for race detection. In PLDI, pages 320– 331, 2006.
[42]
G. Richards, A. Gal, B. Eich, and J. Vitek. Automated construction of JavaScript benchmarks. In OOPSLA, pages 677–694, 2011.
[43]
S. Sarkar, K. Memarian, S. Owens, M. Batty, P. Sewell, L. Maranget, J. Alglave, and D. Williams. Synchronising C/C++ and POWER. In PLDI, pages 311–322, 2012.
[44]
S. Savage, M. Burrows, G. Nelson, P. Sobalvarro, and T. E. Anderson. Eraser: A dynamic data race detector for multithreaded programs. ACM Trans. Comput. Syst., 15(4):391–411, 1997.
[45]
K. Serebryany and T. Iskhodzhanov. ThreadSanitizer: Data race detection in practice. In WBIA, pages 62–71, 2009.
[46]
T. Sorensen and A. F. Donaldson. Exposing errors related to weak memory in GPU applications. In PLDI, pages 100–113, 2016.
[47]
N. Sterling. WARLOCK - A static data race analysis tool. In USENIX Winter, pages 97–106, 1993.
[48]
V. Vafeiadis, T. Balabonski, S. Chakraborty, R. Morisset, and F. Z. Nardelli. Common compiler optimisations are invalid in the C11 memory model and what we can do about it. In POPL, pages 209– 220, 2015.
[49]
J. W. Voung, R. Jhala, and S. Lerner. RELAY: Static race detection on millions of lines of code. In FSE, pages 205–214, 2007.
[50]
J. Ševˇcík, V. Vafeiadis, F. Zappa Nardelli, S. Jagannathan, and P. Sewell. CompCertTSO: A verified compiler for relaxed-memory concurrency. J. ACM, 60(3):22, 2013.
[51]
D. Vyukov. Relacy race detector, visited November 2016. http://www.1024cores.net/home/relacy-race-detector.
[52]
N. Zhang, M. Kusano, and C. Wang. Dynamic partial order reduction for relaxed memory models. In PLDI, pages 250–259, 2015.

Cited By

View all
  • (2022)BiRD: Race Detection in Software Binaries under Relaxed Memory ModelsACM Transactions on Software Engineering and Methodology10.1145/349853831:4(1-29)Online publication date: 12-Jul-2022
  • (2021)MonkeyDB: effectively testing correctness under weak isolation levelsProceedings of the ACM on Programming Languages10.1145/34855465:OOPSLA(1-27)Online publication date: 15-Oct-2021
  • (2020)Detecting semantic violations of lock-free data structures through C++ contractsThe Journal of Supercomputing10.1007/s11227-019-02827-476:7(5057-5078)Online publication date: 1-Jul-2020
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM SIGPLAN Notices
ACM SIGPLAN Notices  Volume 52, Issue 1
POPL '17
January 2017
901 pages
ISSN:0362-1340
EISSN:1558-1160
DOI:10.1145/3093333
Issue’s Table of Contents
  • cover image ACM Conferences
    POPL '17: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages
    January 2017
    901 pages
    ISBN:9781450346603
    DOI:10.1145/3009837
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 the author(s) 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: 01 January 2017
Published in SIGPLAN Volume 52, Issue 1

Check for updates

Author Tags

  1. C++11
  2. concurrency
  3. data races
  4. memory models

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)46
  • Downloads (Last 6 weeks)3
Reflects downloads up to 20 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2022)BiRD: Race Detection in Software Binaries under Relaxed Memory ModelsACM Transactions on Software Engineering and Methodology10.1145/349853831:4(1-29)Online publication date: 12-Jul-2022
  • (2021)MonkeyDB: effectively testing correctness under weak isolation levelsProceedings of the ACM on Programming Languages10.1145/34855465:OOPSLA(1-27)Online publication date: 15-Oct-2021
  • (2020)Detecting semantic violations of lock-free data structures through C++ contractsThe Journal of Supercomputing10.1007/s11227-019-02827-476:7(5057-5078)Online publication date: 1-Jul-2020
  • (2019)Verifying C11 programs operationallyProceedings of the 24th Symposium on Principles and Practice of Parallel Programming10.1145/3293883.3295702(355-365)Online publication date: 16-Feb-2019
  • (2024)Robustness against the C/C++11 Memory ModelProceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis10.1145/3650212.3685549(1881-1885)Online publication date: 11-Sep-2024
  • (2023)Probabilistic Concurrency Testing for Weak Memory ProgramsProceedings of the 28th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 210.1145/3575693.3575729(603-616)Online publication date: 27-Jan-2023
  • (2022)BiRD: Race Detection in Software Binaries under Relaxed Memory ModelsACM Transactions on Software Engineering and Methodology10.1145/349853831:4(1-29)Online publication date: 12-Jul-2022
  • (2021)MonkeyDB: effectively testing correctness under weak isolation levelsProceedings of the ACM on Programming Languages10.1145/34855465:OOPSLA(1-27)Online publication date: 15-Oct-2021
  • (2021)iGUARDProceedings of the ACM SIGOPS 28th Symposium on Operating Systems Principles10.1145/3477132.3483545(49-65)Online publication date: 26-Oct-2021
  • (2021)C11Tester: a race detector for C/C++ atomicsProceedings of the 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems10.1145/3445814.3446711(630-646)Online publication date: 19-Apr-2021
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media