Skip to content

Futex

Category: Synchronization · Status: stub

One line: A Linux kernel facility for building locks: the uncontended case is a single atomic operation in user space, and only a thread that has to wait enters the kernel.

Also called: fast user-space mutex, WaitOnAddress.

How it connects

flowchart LR
  n_futex["Futex"]
  n_mutex["Mutex"]
  n_mutex -->|uses| n_futex
  classDef center stroke-width:3px
  class n_futex center
  classDef outside stroke-dasharray: 4 3
  class n_mutex outside

In each language

C++ std::atomic<T>::wait and notify_one (C++20) block a thread until the atomic is notified and its value has changed
JavaScript Atomics.wait and Atomics.notify are modeled on Linux futexes
The operating system Linux futex(7) ↗: the uncontended case happens entirely in user space; Windows has WaitOnAddress, which waits for the value at an address to change

Where to read more