io_uring_prep_futex_wait(3)
π io_uring_prep_futex_wait β the liburing manual, bestie edition π
okay so. you're in the liburing manual, section 3, and the star of today's show is io_uring_prep_futex_wait. it's giving "make my ring wait on a futex without blocking a thread" and honestly? iconic. let's get into it. π¦
β¨ NAME β¨
io_uring_prep_futex_wait β bestie, it prepares a futex wait request. that's it. that's the whole job. π
πΈ SYNOPSIS πΈ
#include <linux/futex.h>
#include <unistd.h>
#include <liburing.h>
void io_uring_prep_futex_wait(struct io_uring_sqe *sqe,
const uint32_t *futex,
uint64_t val,
uint64_t mask,
uint32_t futex_flags,
unsigned int flags);
look at her. six arguments. main character energy fr fr. β¨
π DESCRIPTION π
so the way that io_uring_prep_futex_wait(3) works is: it preps a futex wait request. you hand it a submission queue entry sqe, and it sets that sqe up to wait on a futex at address futex β but only if it still has the value val. like, no cap, the value has to still match or the wait just doesn't happen. π
on top of that you're passing futex2(2) flags in futex_flags, and the io_uring futex flags in flags.
now, mask β you can set this to a specific bitset mask, and the waking side will match against it to decide who gets woken up. so it's lowkey a little VIP list. ποΈ if you want to always get woken, an application may use FUTEX_BITSET_MATCH_ANY. no faves, everyone gets in. π
heads up bestie:futex_flagsfollows thefutex2(2)flags, not thefutex(2)v1 interface flags. don't mix them up, i'm begging. π
and flags? currently unused, so 0 must be passed. zero. nothing. she's not taking applications right now. π
this function prepares an async futex(2) wait request β go read that man page for the details, it's the source of truth. and ngl, a fun lil fact: the io_uring futex wait request is similar to the FUTEX_WAIT_BITSET operation, because FUTEX_WAIT is a strict subset of that. subset! she contains multitudes. π
Available since kernel 6.7. β
π« RETURN VALUE π«
None. literally none. it returns nothing, it's above such things. π§
π ERRORS π
the CQE res field is where the result of the operation lives. see the related man page for details on possible values. π
and here's the thing that trips people up: synchronous system calls return -1 on failure and set errno to the actual error value β but io_uring never uses errno. instead it returns the negated errno directly in the CQE res field. so if you're out here checking errno after an io_uring op, bestie, no you're not. π check res.
π₯ NOTES π₯
okay so unlike the sync futex syscalls that wait on a futex, io_uring does not support passing in a timeout for the request. sorry. no timeout parameter, she said no. π
instead, applications are encouraged to use a linked timeout to abort the futex request at a given time, if desired. that's the move. link it up. π
π«Ά SEE ALSO π«Ά
io_uring_get_sqe(3)io_uring_submit(3)io_uring_prep_futex_waitv(3)io_uring_prep_futex_wake(3)io_uring_prep_link_timeout(3)futex(2)futex2(2)
and that's the whole page, bestie, you ate it. π
this was liburing-2.5, dated Sep 29, 2023, and it's still serving io_uring_prep_futex_wait(3) realness to this very day. go prep some sqes, ily, bye πβ¨
π¦ where this page comes from
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- arch rolling: liburing 2.15-1 Β· GPL-2.0-only WITH Linux-syscall-note OR MIT AND LGPL-2.0-or-later AND MIT
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- nixpkgs unstable: liburing 2.14
- ubuntu resolute: liburing-dev 2.14-1
- ubuntu stonking: liburing-dev 2.15-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2022 Jens Axboe <axboe@kernel.dk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms