skip to main content
research-article

Dynamic race detection for C++11

Published:01 January 2017Publication History
Skip Abstract Section

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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. J. Alglave, D. Kroening, V. Nimal, and M. Tautschnig. Software verification for weak memory via program transformation. In ESOP, pages 512–532, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  6. M. Batty, S. Owens, S. Sarkar, P. Sewell, and T. Weber. Mathematizing C++ concurrency. In POPL, pages 55–66, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. M. Batty, A. F. Donaldson, and J. Wickerson. Overhauling SC atomics in C11 and OpenCL. In POPL, pages 634–648, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. J. C. Blanchette, T. Weber, M. Batty, S. Owens, and S. Sarkar. Nitpicking C++ concurrency. In PPDP, pages 113–124, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. S. Chakraborty and V. Vafeiadis. Validating optimizations of concurrent C/C++ programs. In CGO, pages 216–226, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. M. Doko and V. Vafeiadis. A program logic for C11 memory fences. In VMCAI, pages 413–430, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. T. Elmas, S. Qadeer, and S. Tasiran. Goldilocks: a race-aware Java runtime. Commun. ACM, 53(11):85–92, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. D. R. Engler and K. Ashcraft. RacerX: effective, static detection of race conditions and deadlocks. In SOSP, pages 237–252, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. C. Flanagan and S. N. Freund. FastTrack: efficient and precise dynamic race detection. In PLDI, pages 121–133, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. C. Flanagan and S. N. Freund. Adversarial memory for detecting destructive races. In PLDI, pages 244–254, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. C. Flanagan and P. Godefroid. Dynamic partial-order reduction for model checking software. In POPL, pages 110–121, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Google. KernelThreadSanitizer, a fast data race detector for the Linux kernel, visited November 2016.Google ScholarGoogle Scholar
  19. https://github.com/google/ ktsan.Google ScholarGoogle Scholar
  20. ISO/IEC. Programming languages – C. International standard 9899:2011, 2011.Google ScholarGoogle Scholar
  21. ISO/IEC. Programming languages – C++. International standard 14882:2011, 2011.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. H. Jin, T. Yavuz-Kahveci, and B. A. Sanders. Java memory modelaware model checking. In TACAS, pages 220–236, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. R. Krebbers and F. Wiedijk. A typed C11 semantics for interactive theorem proving. In CPP, pages 15–27, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. O. Lahav, N. Giannarakis, and V. Vafeiadis. Taming release-acquire consistency. In POPL, pages 649–662, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. L. Lamport. Time, clocks, and the ordering of events in a distributed system. Commun. ACM, 21(7):558–565, 1978. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. C. Lidbury and A. F. Donaldson. Companion webiste for reproducibility of experiments, 2017. http://multicore.doc.ic.ac. uk/projects/tsan11/.Google ScholarGoogle Scholar
  28. C. Lidbury and A. F. Donaldson. Dynamic race detection for C++11: Extended version, 2017.Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. https://www.doc.ic.ac.uk/ ~afd/homepages/papers/pdfs/2017/POPLExtended.pdf.Google ScholarGoogle Scholar
  30. F. Mattern. Virtual time and global states of distributed systems. In Proc. Workshop on Parallel and Distributed Algorithms, pages 215– 226, 1988.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. K. Nienhuis, K. Memarian, and P. Sewell. An operational semantics for C/C++11 concurrency. In OOPSLA, pages 111–128, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. B. Norris and B. Demsky. CDSchecker: checking concurrent data structures written with C/C++ atomics. In OOPSLA, pages 131–150, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. A. Podkopaev, I. Sergey, and A. Nanevski. Operational aspects of C/C++ concurrency. CoRR, abs/1606.01400, 2016.Google ScholarGoogle Scholar
  38. D. Poetzl and D. Kroening. Formalizing and checking thread refinement for data-race-free execution models. In TACAS, pages 515–530, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. E. Pozniansky and A. Schuster. Efficient on-the-fly data race detection in multihreaded C++ programs. In PPoPP, pages 179–190, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. P. Pratikakis, J. S. Foster, and M. Hicks. LOCKSMITH: contextsensitive correlation analysis for race detection. In PLDI, pages 320– 331, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. G. Richards, A. Gal, B. Eich, and J. Vitek. Automated construction of JavaScript benchmarks. In OOPSLA, pages 677–694, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. K. Serebryany and T. Iskhodzhanov. ThreadSanitizer: Data race detection in practice. In WBIA, pages 62–71, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. T. Sorensen and A. F. Donaldson. Exposing errors related to weak memory in GPU applications. In PLDI, pages 100–113, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. N. Sterling. WARLOCK - A static data race analysis tool. In USENIX Winter, pages 97–106, 1993.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. D. Vyukov. Relacy race detector, visited November 2016. http://www.1024cores.net/home/relacy-race-detector.Google ScholarGoogle Scholar
  52. N. Zhang, M. Kusano, and C. Wang. Dynamic partial order reduction for relaxed memory models. In PLDI, pages 250–259, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Dynamic race detection for C++11

        Recommendations

        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 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

          Copyright © 2017 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 1 January 2017

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!