Detecting semantic violations of lock-free data structures through C++ contracts

  • Javier López-Gómez
  • David del Rio Astorga
  • Manuel F. Dolz
  • Javier FernándezEmail author
  • J. Daniel García


The use of synchronization mechanisms in multithreaded applications is essential on shared-memory multi-core architectures. However, debugging parallel applications to avoid potential failures, such as data races or deadlocks, can be challenging. Race detectors are key to spot such concurrency bugs; nevertheless, if lock-free data structures are used, these may emit a significant number of false positives. In this paper, we present a framework for semantic violation detection of lock-free data structures which makes use of contracts, a novel feature of the upcoming C++20, and a customized version of the ThreadSanitizer race detector. We evaluate the detection accuracy of the framework in terms of false positives and false negatives leveraging some synthetic benchmarks which make use of the SPSC and MPMC lock-free queue structures from the Boost C++ library. Thanks to this framework, we are able to check the correct use of lock-free data structures, thus reducing the number of false positives.


Parallel programming Semantic violation detection C++ contracts Lock-free data structures 



This work has been partially funded by the Spanish Ministry of Economy and Competitiveness through Project Grant TIN2016-79637-P (BigHPC—Towards Unification of HPC and Big Data Paradigms) and the European Commission through Grant No. 801091 (ASPIDE—Exascale programmIng models for extreme data processing).


  1. 1.
    Artho C, Havelund K, Biere A (2003) High-level data races. Softw Test Verif Reliab 13(4):207–227CrossRefGoogle Scholar
  2. 2.
    Blechmann T (2011) Chapter 17. Boost.Lockfree.
  3. 3.
    Borkar S (2010) The exascale challenge. In: 2010 international symposium on VLSI design automation and test (VLSI-DAT), pp 2–3.
  4. 4.
    Boyapati C, Lee R, Rinard M (2002) Ownership types for safe programming: preventing data races and deadlocks. In: ACM SIGPLAN notices, vol 37, no. 11. ACM, pp 211–230Google Scholar
  5. 5.
    Choi J, Dukhan M, Liu X, Vuduc R (2014) Algorithmic time, energy, and power on candidate HPC compute building blocks. In: 2014 IEEE 28th international on Parallel and distributed processing symposium, pp 447–457.
  6. 6.
    Dolz MF, Del Rio Astorga D, Fernández J, Torquati M, García JD, García-Carballeira F, Danelutto M (2017) Enabling semantics to improve detection of data races and misuses of lock-free data structures. Concurr Comput Pract Exp. Google Scholar
  7. 7.
    Dongol B (2006) Formalising progress properties of non-blocking programs. In: Liu Z, He J (eds) Formal methods and software engineering. Springer, Berlin, pp 284–303CrossRefGoogle Scholar
  8. 8.
    Engler D, Ashcraft K (2003) RacerX: effective, static detection of race conditions and deadlocks. SIGOPS Oper Syst Rev 37(5):237–252. CrossRefGoogle Scholar
  9. 9.
    Giacomoni J, Moseley T, Vachharajani M (2008) Fastforward for efficient pipeline parallelism: a cache-optimized concurrent lock-free queue. In: Proceedings of the 13th ACM SIGPLAN symposium on principles and practice of parallel programming, PPoPP ’08. ACM, NY, pp 43–52.
  10. 10.
  11. 11.
    Kokologiannakis M, Lahav O, Sagonas K, Vafeiadis V (2017) Effective stateless model checking for c/c++ concurrency. Proc ACM Program Lang 2(1):17:1–17:32. Google Scholar
  12. 12.
    Lamport L (1978) Time, clocks, and the ordering of events in a distributed system. Commun ACM 21(7):558–565. CrossRefzbMATHGoogle Scholar
  13. 13.
    Lamport L (1979) How to make a multiprocessor computer that correctly executes multiprocess programs. IEEE Trans Comput 28(9):690–691. CrossRefzbMATHGoogle Scholar
  14. 14.
    Lattner C, Adve V (2004) LLVM: A compilation framework for lifelong program analysis & transformation. In: Proceedings of the international symposium on code generation and optimization: feedback-directed and runtime optimization, CGO ’04. IEEE Computer Society, Washington, p 75Google Scholar
  15. 15.
    Lidbury C, Donaldson AF (2017) Dynamic race detection for c++11. SIGPLAN Not 52(1):443–457. CrossRefzbMATHGoogle Scholar
  16. 16.
    Lu S, Park S, Seo E, Zhou Y (2008) Learning from mistakes: a comprehensive study on real world concurrency bug characteristics. In: Proceedings of the 13th International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS XIII. ACM, New York, pp 329–339.
  17. 17.
    Michael MM, Scott ML (1996) Simple, fast, and practical non-blocking and blocking concurrent queue algorithms. In: Proceedings of the fifteenth annual ACM symposium on principles of distributed computing, PODC ’96. ACM, New York, pp 267–275Google Scholar
  18. 18.
    Norris B, Demsky B (2013) CDSchecker: checking concurrent data structures written with C/C++ atomics. SIGPLAN Not 48(10):131–150. CrossRefGoogle Scholar
  19. 19.
    Norris B, Demsky B (2016) A practical approach for model checking C/C++11 Code. ACM Trans Program Lang Syst 38(3):10:1–10:51. CrossRefGoogle Scholar
  20. 20.
    O’Callahan R, Choi JD (2003) Hybrid dynamic data race detection. SIGPLAN Not 38(10):167–178CrossRefGoogle Scholar
  21. 21.
    Ou P, Demsky B (2017) Checking concurrent data structures under the C/C++11 memory model. SIGPLAN Not 52(8):45–59. CrossRefGoogle Scholar
  22. 22.
    Reis GD, Garcia JD, Lakos J, Meredith A, Myers N, Stroustrup B (2018) Support for contract based programming in C++. ISO/IEC JTC1/SC22/WG21 Working Paper, June 2018Google Scholar
  23. 23.
    Savage S, Burrows M, Nelson G, Sobalvarro P, Anderson T (1997) Eraser: a dynamic data race detector for multithreaded programs. ACM Trans Comput Syst (TOCS) 15(4):391–411CrossRefGoogle Scholar
  24. 24.
    Schweizer H, Besta M, Hoefler T (2015) Evaluating the cost of atomic operations on modern architectures. In: 24th International Conference on Parallel Architectures and Compilation (PACT’15). ACMGoogle Scholar
  25. 25.
    Serebryany K, Potapenko A, Iskhodzhanov T, Vyukov D (2012) Dynamic race detection with LLVM compiler. In: Khurshid S, Sen K (eds) Runtime verification. Springer, Berlin, pp 110–114CrossRefGoogle Scholar
  26. 26.
    Shalev O, Shavit N (2006) Split-ordered lists: lock-free extensible hash tables. J ACM 53(3):379–405MathSciNetCrossRefzbMATHGoogle Scholar
  27. 27.
    Xie X, Xue J (2011) Acculock: accurate and efficient detection of data races. In: Proceedings of the 9th annual IEEE/ACM international symposium on code generation and optimization, CGO ’11. IEEE Computer Society, Washington, pp 201–212Google Scholar
  28. 28.
    Zhou P, Teodorescu R, Zhou Y (2007) Hard: Hardware-assisted lockset-based race detection. In: Proceedings of the 2007 IEEE 13th international symposium on high performance computer architecture, HPCA ’07. IEEE Computer Society, Washington, pp 121–132.

Copyright information

© Springer Science+Business Media, LLC, part of Springer Nature 2019

Authors and Affiliations

  1. 1.Department of Computer ScienceUniversidad Carlos III de MadridLeganésSpain
  2. 2.Department of Engineering and Computer ScienceUniversitat Jaume I de CastellóCastellónSpain

Personalised recommendations