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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
References
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
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
Benderski, E.: Basics of futexes (2018). https://eli.thegreenplace.net/2018/basics-of-futexes/. Accessed 10 Jan 2023
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)
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
Denis-Courmont, R.: Condition variable with futex (2020). https://www.remlab.net/op/futex-condvar.shtml. Accessed 10 Jan 2023
Drepper, U.: Futexes are tricky (2011). https://www.akkadia.org/drepper/futex.pdf. Accessed 10 Jan 2023
Evrard, H., Donaldson, A.: Model checking futexes: code examples (2022). https://github.com/mc-imperial/modelcheckingfutexes. Accessed 16 Jan 2022
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
Futex manual page section 2 (system calls) (2023). https://man7.org/linux/man-pages/man2/futex.2.html. Accessed 16 Jan 2023
Futex manual page section 7 (miscellaneous) (2023). https://man7.org/linux/man-pages/man7/futex.7.html. Accessed 16 Jan 2023
Hamberg, R., Vaandrager, F.: Using model checkers in an introductory course on operating systems. ACM SIGOPS Operat. Syst. Rev. 42(6), 101–111 (2008)
Holzmann, G.: The SPIN model checker: primer and reference manual. Addison-Wesley Professional, 1st edn. (2011)
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
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
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)
Mechanical sympathy email group, discussion titled linux futex_wait() bug (2015). https://groups.google.com/g/mechanical-sympathy/c/QbmpZxp6C64. Accessed 16 Jan 2023
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
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)