Generated by GPT-5-mini| futex | |
|---|---|
| Name | futex |
| Developer | Linus Torvalds / Linux kernel |
| Introduced | 2002 |
| Stable release | Linux 2.6 series |
| Operating system | Linux kernel |
| License | GNU General Public License |
futex
futex is a kernel-assisted synchronization primitive used in Linux kernel environments to implement fast user-space locking. It combines user-space atomic operations with occasional kernel mediation to provide low-overhead primitives for threads in programs such as those developed by teams at Google, Red Hat, Intel Corporation, and Facebook. Futexes are central to threading libraries like GNU C Library and projects such as glibc-based implementations, and they interact with subsystems maintained by contributors including Linus Torvalds and Ingo Molnár.
Futexes provide a hybrid mechanism that lets user-space code implement locks and condition variables while relying on the kernel only when contention requires blocking, similar in purpose to primitives used in POSIX threading and in systems influenced by research from Microsoft Research, Sun Microsystems, and Carnegie Mellon University. The design aims to be compatible with threading APIs used by NPTL and implementations in glibc and musl libc, enabling integration with projects like systemd and runtimes such as Java Virtual Machine and Go (programming language). Futex operations are exposed via system calls that were standardized in the Linux kernel community and are used by userspace projects including Firefox, Chromium (web browser), and MySQL.
The futex mechanism relies on a small integer stored in user-space memory; user code performs atomic operations (typically compare-and-swap) and only invokes the kernel with futex system calls when it must wait or wake, a pattern similar to constructs in research by David Mazières and Frédéric B. Schneider. This two-level approach reduces syscall frequency for uncontended fast paths, mirroring strategies used in lock-free programming research at institutions such as MIT and UC Berkeley. Kernel-side operations map to wait queues keyed by the user-space address, and the kernel manages blocking via task management code contributed by maintainers like Theodore Ts'o and Andrew Morton.
The futex interface was introduced into the Linux kernel mainline in the early 2000s and has evolved across versions maintained by contributors including Linus Torvalds, Greg Kroah-Hartman, and subsystem maintainers. Implementation details appear in kernel files within the Linux kernel source tree and interact with subsystems such as sched core and mm (memory management). The interface provides operations like FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE and newer features for priority inheritance contributed by teams at IBM and Red Hat. Various kernel vulnerabilities and bugs have been tracked in advisories referenced by CVE entries and fixed in releases coordinated by distributors such as Debian, Ubuntu, and CentOS.
Futexes are designed to minimize context switches and avoid kernel involvement in the uncontended case, an optimization relied upon by high-performance servers developed by Netflix, Amazon Web Services, and Twitter. Benchmarks in user-space runtimes like Node.js, OpenJDK, and Nginx show futex-based locks outperform heavy-weight kernel locks under typical workloads, similar to comparative studies at Stanford University and ETH Zurich. Scalability depends on kernel wait-queue management and scheduler interactions maintained by Ingo Molnár and Thomas Gleixner, and performance tuning is often performed by developers working on Linux kernel performance tooling such as perf and systemtap.
Correct use of futexes requires careful synchronization to avoid priority inversion, deadlocks, and race conditions; techniques overlap with those studied at Carnegie Mellon University and in textbooks by Andrew S. Tanenbaum and Herbert Schildt. The futex syscall surface has been an attack vector in some CVE reports, prompting mitigations in distributions like Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Kernel developers including Kees Cook and Cristian Rodríguez have proposed hardening patches, while formal verification efforts at Microsoft Research and academic groups aim to model futex semantics for correctness proofs.
Alternatives to futex-based synchronization include pure user-space lock-free algorithms popularized by researchers at MIT and EPFL, and kernel-mediated primitives such as futex-adjacent constructs like futexes' conceptual counterparts in Windows NT (e.g., WaitForSingleObject), FreeBSD kqueue-based mechanisms, and Solaris pthreads implementations. Libraries like Boost (C++) and languages' runtimes including Rust (programming language)'s standard library provide abstractions that may use futexes on Linux or alternative primitives on other operating systems maintained by projects such as FreeBSD and OpenBSD.