Skip to main content

Model Checking Futexes

  • Conference paper
  • First Online:
Model Checking Software (SPIN 2023)

Abstract

The futex Linux system call enables implementing performant inter-thread synchronisation primitives, such as mutexes and condition variables. However, the futex system call is notoriously tricky to use correctly. In this case study, we use the Spin model checker to verify safety properties of a number of futex-based mutex and condition variable implementations. We show how model checking is able to detect bugs that affected real-world implementations, and confirm current implementations are correct. The Promela models we have developed are available as open source, and may be useful as teaching material for classes that cover futex-based synchronisation primitives, and as a template on how to perform formal verification on new synchronisation primitive designs.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

Notes

  1. 1.

    https://man7.org/linux/man-pages/man2/futex.2.html.

References

  1. Android: Bionic C library, pthread_cond implementation (2023). https://android.googlesource.com/platform/bionic/+/refs/tags/android-13.0.0_r24/libc/bionic/pthread_cond.cpp. Accessed 10 Jan 2023

  2. Bar-David, Y., Taubenfeld, G.: Automatic discovery of mutual exclusion algorithms. In: Fich, F.E. (ed.) DISC 2003. LNCS, vol. 2848, pp. 136–150. Springer, Heidelberg (2003). https://doi.org/10.1007/978-3-540-39989-6_10

    Chapter  Google Scholar 

  3. Benderski, E.: Basics of futexes (2018). https://eli.thegreenplace.net/2018/basics-of-futexes/. Accessed 10 Jan 2023

  4. Bogunovic, N., Pek, E.: Verification of mutual exclusion algorithms with SMV system. In: The IEEE Region 8 EUROCON 2003. Computer as a Tool. vol. 2, pp. 21–25. IEEE (2003)

    Google Scholar 

  5. Clarke, E., Kroening, D., Lerda, F.: A tool for checking ANSI-C programs. In: Jensen, K., Podelski, A. (eds.) TACAS 2004. LNCS, vol. 2988, pp. 168–176. Springer, Heidelberg (2004). https://doi.org/10.1007/978-3-540-24730-2_15

    Chapter  MATH  Google Scholar 

  6. Denis-Courmont, R.: Condition variable with futex (2020). https://www.remlab.net/op/futex-condvar.shtml. Accessed 10 Jan 2023

  7. Drepper, U.: Futexes are tricky (2011). https://www.akkadia.org/drepper/futex.pdf. Accessed 10 Jan 2023

  8. Evrard, H., Donaldson, A.: Model checking futexes: code examples (2022). https://github.com/mc-imperial/modelcheckingfutexes. Accessed 16 Jan 2022

  9. Franke, H., Russell, R., Kirkwood, M.: Fuss, futexes and furwocks: fast userlevel locking in Linux. In: Ottawa Linux Symposium 2002, pp. 479–495 (2002). https://www.kernel.org/doc/ols/2002/ols2002-pages-479-495.pdf. Accessed 10 Jan 2022

  10. Futex manual page section 2 (system calls) (2023). https://man7.org/linux/man-pages/man2/futex.2.html. Accessed 16 Jan 2023

  11. Futex manual page section 7 (miscellaneous) (2023). https://man7.org/linux/man-pages/man7/futex.7.html. Accessed 16 Jan 2023

  12. Hamberg, R., Vaandrager, F.: Using model checkers in an introductory course on operating systems. ACM SIGOPS Operat. Syst. Rev. 42(6), 101–111 (2008)

    Article  Google Scholar 

  13. Holzmann, G.: The SPIN model checker: primer and reference manual. Addison-Wesley Professional, 1st edn. (2011)

    Google Scholar 

  14. Kokologiannakis, M., Vafeiadis, V.: BAM: efficient model checking for barriers. In: Echihabi, K., Meyer, R. (eds.) NETYS 2021. LNCS, vol. 12754, pp. 223–239. Springer, Cham (2021). https://doi.org/10.1007/978-3-030-91014-3_16

    Chapter  Google Scholar 

  15. Mateescu, R., Serwe, W.: A study of shared-memory mutual exclusion protocols using CADP. In: Kowalewski, S., Roveri, M. (eds.) FMICS 2010. LNCS, vol. 6371, pp. 180–197. Springer, Heidelberg (2010). https://doi.org/10.1007/978-3-642-15898-8_12

    Chapter  Google Scholar 

  16. Mateescu, R., Serwe, W.: Model checking and performance evaluation with CADP illustrated on shared-memory mutual exclusion protocols. Sci. Comput. Program. 78(7), 843–861 (2013)

    Google Scholar 

  17. Mechanical sympathy email group, discussion titled linux futex_wait() bug (2015). https://groups.google.com/g/mechanical-sympathy/c/QbmpZxp6C64. Accessed 16 Jan 2023

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Hugues Evrard .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Evrard, H., Donaldson, A.F. (2023). Model Checking Futexes. In: Caltais, G., Schilling, C. (eds) Model Checking Software. SPIN 2023. Lecture Notes in Computer Science, vol 13872. Springer, Cham. https://doi.org/10.1007/978-3-031-32157-3_3

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-32157-3_3

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-32156-6

  • Online ISBN: 978-3-031-32157-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics