futex_wait_setup(9)
π futex_wait_setup(9) π
okay so bestie, welcome to the Kernel API Manual page for futex_wait_setup(9) β yes that's the literal title, we're doing this, and honestly it's lowkey iconic that you're even here. grab a snack π
β¨ NAME β¨
futex_wait_setup β the "get ready to wait on a futex" pre-game ritual π
πΈ SYNOPSIS πΈ
int futex_wait_setup (u32 __user *uaddr , u32 val , unsigned int flags ,
struct futex_q *q , union futex_key *key2 , struct task_struct *task );
ngl, look at all those parameters. main character energy fr fr π
π¦ ARGUMENTS π¦
uaddrβ the futex userspace address. like, where the actual futex lives in userspace πvalβ the expected value. the vibe we're checking against β¨flagsβ futex flags (FLAGS_SHARED, etc.).FLAGS_SHAREDis literally called out by name in the original, so yes it gets a shoutout π«Άqβ the associatedfutex_q. its designated buddy πkey2β the secondfutex_key, used if this is for requeue PI. only relevant in that case, iykyk π₯taskβ the task that's queueing up this futex. the one doing the queueing π
π DESCRIPTION π
kay so here's the whole thing: it sets up the futex_q and locates the hash_bucket. then it gets the futex value and compares it against the expected value. atomic faults? handled internally, no cap, we don't make it your problem π
and the big one β return with the hb lock held on success, and unlocked on failure. that's the contract, bestie, do not forget it π
β RETURN β
0βuaddrcontainsvaland the hb has been locked π slay<0β on error, and the hb is unlocked. a possible reason: theuaddrcan not be read, does not contain the expected value, or is not properly aligned. three whole ways to fail, iconic of it honestly π
π SEE ALSO π
go read the kernel file ./kernel/futex/waitwake.c and then these besties:
futex_do_wait(9)futex_unqueue_multiple(9)futex_wait_multiple_setup(9)futex_sleep_multiple(9)futex_wait_multiple(9)
ok tiny warning moment: on that0return you are holding the hb lock, so please please please remember to do something about it. and<0means it's already unlocked β don't go unlocking a lock you don't hold, that's not the vibe π
and that's the page!! from ./kernel/futex, dated October 2026, in the Kernel API Manual π bye bestie, go wait on that futex responsibly π§πΈ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms