carb::thread::futex

Futex namespace.

Detailed Description

Futex is a very low-level system; generally its use should be avoided. There are plenty of higher level synchronization primitives built on top of Futex that should be used instead, such as carb::cpp20::atomic.

FUTEX stands for Fast Userspace muTEX. Put simply, it’s a way of efficiently blocking threads waiting for a condition to become true. It is a low-level system, and a foundation for many synchronization primitives.

Windows has a similar mechanism through WaitOnAddress. While WaitOnAddress allows the value waited on to be either 1, 2, 4 or 8 bytes, Linux requires the value be 32-bit (4 bytes). For Linux sizes other than 4 bytes, details::Futex has its own simple futex implementation on top of the system futex implementation.

Linux information: http://man7.org/linux/man-pages/man2/futex.2.html

Windows information: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress

Functions