futex_cmpxchg(9)
π futex_cmpxchg(9) β the Kernel API Manual, bestie edition
Okay so picture this: it's a futex_cmpxchg(9) kind of day, and you're about to do an atomic compare and exchange. Yes, atomic. As in, no other thread can sneak in and ruin the vibe. Periodt. π
β¨ SYNOPSIS β¨
u_int32_t futex_cmpxchg (futex_t *uaddr , u_int32_t oldval , u_int32_t
newval );
Look at her. Three args, one u_int32_t coming back at you. She's simple, she's iconic, she does exactly one thing and does it flawlessly. π
πΈ ARGUMENTS πΈ
uaddrβ the address of the futex you wanna modify. It's giving "main character address" energy, honestly. This is the spot. π₯oldvalβ the value you're expecting the futex to have. Like, if it isn't this, the whole thing doesn't go down. No cap.newvalβ the new value you're tryna assign to that futex. Your glow-up value. β¨
π¦ DESCRIPTION π¦
So basically this bad boy implements cmpxchg using the gcc atomic builtins. That's the whole thing. That's the assignment. π
If you want the lore, the original docs live here:
http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
And here's the part that matters: it returns the old futex value. Like, whatever was sitting there before you made your move. Lowkey obsessed with that β it lets you know if your exchange actually ate or if someone beat you to it. π
π₯ SEE ALSO π₯
The kernel file, bestie β go read it, iykyk:
Kernel file ./tools/testing/selftests/futex/include/futextest.h
And the whole futex friend group, all here, all slaying:
futex(9)futex_wait(9)futex_wake(9)futex_wait_bitset(9)futex_wake_bitset(9)futex_lock_pi(9)futex_unlock_pi(9)futex_wake_op(9)futex_requeue(9)futex_cmp_requeue(9)futex_wait_requeue_pi(9)futex_cmp_requeue_pi(9)futex_dec(9)futex_inc(9)futex_set(9)
fr fr, this is the Kernel API Manual, dated October 2026, and the source line trails off at ./tools/testing/selftests/fute... β that's not me being mysterious, that's just literally where the footer cuts off. π«Ά
Okay that's the whole page, bestie. Atomic compare and exchange, documented, understood, and honestly? She ate. π β¨ππ¦πΈππ₯π
π¦ 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