A futex is a fast user space mutex that allows user space programs to handle concurrency lock protection mostly from user space, avoiding expensive system calls. On contention, it still requires system calls but it does not need to make them in the non-contended case. It is implemented by sharing a 4 byte user space memory location with the kernel and any other process that requires the synchronization provided by the lock. Implementing this is not trivial. There are lots of hidden gotchas that the kernel must take care of. The futex system call was first introduced into Linux 2.5.6 in 2002. Since then, there’s been a lot of enhancements made to the code as well as new obstacles to overcome.
This talk will go into how a futex is implemented, the various versions of it, and the horror stories that caused those that worked on it to age decades for the few weeks they spent on it.
Steven ROSTEDT