futex_cmpxchg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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:


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