FUTEX_WAIT_BITSET(2const)
π FUTEX_WAIT_BITSET β selective futex waiting and waking π
okay bestie, listen up. this is the FUTEX_WAIT_BITSET(2const) page, aka the futex glow-up where you get to be selective about who you wake up. no more shouting into the void, we're doing targeted DMs now. β¨
πΈ NAME πΈ
FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET β selective futex waiting and waking
like, waiting and waking, but with β¨tasteβ¨. you pick exactly who gets the notification.
π LIBRARY π
Standard C library (libc, -lc)
the classic. she's been here forever and she ate. π
π« SYNOPSIS π«
#include <linux/futex.h> /* Definition of FUTEX_* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
long syscall(SYS_futex, uint32_t *uaddr, FUTEX_WAIT_BITSET, uint32_t val,
const struct timespec *timeout, NULL,
uint32_t val3);
long syscall(SYS_futex, uint32_t *uaddr, FUTEX_WAKE_BITSET, uint32_t val,
NULL, NULL,
uint32_t val3);
not me flexing two syscall signatures like it's nothing π the NULL in position five is doing NOTHING and living its best life fr.
π¦ DESCRIPTION π¦
π FUTEX_WAIT_BITSET
okay so this one is literally FUTEX_WAIT(2const) but with a lil extra something β val3 is a 32-bit bit mask that gets handed to the kernel. and here's the rule that will humble you: at least one bit must be set. not zero. never zero. (we'll get to that in ERRORS, and it is not a vibe.) π«Ά
that bit mask gets stored in the kernel-internal state of the waiter. and then? see the FUTEX_WAKE_BITSET description below for the whole tea.
if timeout is not NULL, the structure it points to specifies an absolute timeout for the wait operation. if timeout is NULL, the operation can block indefinitely. so like, forever, bestie. no alarm set. π
π FUTEX_WAKE_BITSET
this one is the same as FUTEX_WAKE(2const) except that the val3 argument provides a 32-bit bit mask to the kernel. again: at least one bit must be set. the mask is used to select which waiters should be woken up.
and the selection process? it's a bitwise AND of:
- the "wake" bit mask (that's the value in
val3) - the bit mask stored in the kernel-internal state of the waiter (the "wait" bit mask, set using
FUTEX_WAIT_BITSET)
all the waiters where the AND result is nonzero get woken up. the remaining waiters are left sleeping. periodt. π΄
the effect of FUTEX_WAIT_BITSET and FUTEX_WAKE_BITSET is to allow selective wake-ups among multiple waiters that are blocked on the same futex. cute right? BUT β and this is the part where I need you to sit down β depending on the use case, using this bit-mask multiplexing feature on a futex can be less efficient than simply using multiple futexes. why? because bit-mask multiplexing requires the kernel to check all waiters on a futex, including the ones who are not interested in being woken up (i.e., they don't have the relevant bit set in their "wait" bit mask). π like scrolling through the entire group chat for a message that wasn't even for you.
the constant FUTEX_BITSET_MATCH_ANY, which corresponds to all 32 bits set in the bit mask, can be used as the val3 argument for FUTEX_WAIT_BITSET and FUTEX_WAKE_BITSET. and other than the differences in how the timeout argument is handled, the FUTEX_WAIT(2const) operation is equivalent to FUTEX_WAIT_BITSET with val3 specified as FUTEX_BITSET_MATCH_ANY β that is, allow a wake-up by any waker. similarly, FUTEX_WAKE(2const) is equivalent to FUTEX_WAKE_BITSET with val3 specified as FUTEX_BITSET_MATCH_ANY β that is, wake up any waiter(s). no exclusivity, everybody's invited. π
π₯ RETURN VALUE π₯
on error, -1 is returned, and errno is set to indicate the error. classic.
the return value on success depends on the operation, as described in the following list:
FUTEX_WAIT_BITSETβ returns0if the caller was woken up. seeFUTEX_WAIT(2const)for how to interpret this correctly in practice (yes, really, go read it, don't just trust the zero π).FUTEX_WAKE_BITSETβ returns the number of waiters that were woken up.
π ERRORS π
also see futex(2).
EAGAINorEWOULDBLOCKβ (FUTEX_WAIT_BITSET) the value pointed to byuaddrwas not equal to the expected valuevalat the time of the call.EFAULTβtimeoutdid not point to a valid user-space address.EINTRβ aFUTEX_WAIT_BITSEToperation was interrupted by a signal (seesignal(7)). before Linux 2.6.22, this error could also be returned for a spurious wakeup; since Linux 2.6.22, this no longer happens. glow-up confirmed. β¨EINVALβ the suppliedtimeoutargument was invalid (tv_secwas less than zero, ortv_nsecwas not less than1,000,000,000).EINVALβuaddr2does not point to a valid objectβthat is, the address is not four-byte-aligned.EINVALβ the bit mask supplied inval3is zero. (told you bestie. at least. one. bit. π€)EINVALβ (FUTEX_WAKE_BITSET) the kernel detected an inconsistency between the user-space state atuaddrand the kernel stateβthat is, it detected a waiter which waits inFUTEX_LOCK_PI(2const)orFUTEX_LOCK_PI2(2const)onuaddr.ETIMEDOUTβ the timeout expired before the operation completed.
yes there are four separate EINVAL entries. no that is not a typo. the kernel has range. π
β STANDARDS β
Linux. that's it, that's the whole standard. π
π HISTORY π
Linux 2.6.25. vintage but make it iconic.
π SEE ALSO π
and that's the whole page, bestie!! this one's from Linux man-pages 6.20, dated 2026-02-10, and it's the FUTEX_WAIT_BITSET(2const) page β go set some bits and wake exactly the right people, love you, bye π«Άπ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms