FUTEX_TRYLOCK_PI(2const)

✨ FUTEX_TRYLOCK_PI ✨

okay so bestie, welcome to futex_trylock_pi(2const) β€” the manual page for the little syscall operation that's like "hey kernel, please try to grab this priority-inheritance lock for me, no waiting around tho" 🫢


πŸ’– NAME πŸ’–

FUTEX_TRYLOCK_PI β€” try to lock a priority-inheritance futex

πŸŽ€ LIBRARY πŸŽ€

Standard C library (libc, -lc)

🌸 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_TRYLOCK_PI);

πŸ¦‹ DESCRIPTION πŸ¦‹

So this op tries to acquire the lock sitting at uaddr. You only reach for it when your user-space atomic acquire already flopped because the futex word was not 0. Like, you tried, it said no, and now you're knocking on the kernel's door πŸšͺ

And here's the tea β˜• β€” the kernel has access to more state information than user space does. So acquisition of the lock might actually succeed when the kernel does it, even in cases where the futex word (i.e., the state information accessible to user space) is holding stale state β€” specifically FUTEX_WAITERS and/or FUTEX_OWNER_DIED. This can happen when the owner of the futex straight-up died πŸ’€ User space literally cannot handle this condition in a race-free manner, but the kernel can fix this up and acquire the futex. Iconic behaviour, honestly.

πŸ‘‘ RETURN VALUE πŸ‘‘

On error, -1 is returned, and errno is set to indicate the error.

On success, FUTEX_TRYLOCK_PI returns 0 if the futex was successfully locked. slay ✨

πŸ’… ERRORS πŸ’…

See futex(2).

  • EAGAIN β€” the futex owner thread ID of uaddr is about to exit, but hasn't handled the internal state cleanup yet. Try again, bestie.
  • EDEADLK β€” the futex word at uaddr is already locked by the caller. yes, by you. awkward πŸ™ˆ
  • EINVAL β€” the kernel detected an inconsistency between the user-space state at uaddr and the kernel state. This means either state corruption, or the kernel found a waiter on uaddr that's waiting via FUTEX_WAIT(2const) or FUTEX_WAIT_BITSET(2const).
  • ENOMEM β€” the kernel could not allocate memory to hold state information. the budget ran out 😭
  • ENOSYS β€” a run-time check determined that the operation is not available. The PI-futex operations are not implemented on all architectures and are not supported on some CPU variants. so if you're on the wrong chip, this is just not happening.
  • EPERM β€” the caller is not allowed to attach itself to the futex at uaddr. (This may be caused by a state corruption in user space.)
  • ESRCH β€” the thread ID in the futex word at uaddr does not exist. ghost thread πŸ‘»

🌈 STANDARDS 🌈

Linux.

⭐ HISTORY ⭐

Linux 2.6.18.

πŸ”₯ SEE ALSO πŸ”₯

futex(2)


ngl if you made it this far you're lowkey a kernel girlie now πŸ’œ go read futex(2) next, it's giving required reading, iykyk

mwah πŸ’‹ this page is from Linux man-pages 6.20, dated 2025-09-21 β€” periodt, that's the whole FUTEX_TRYLOCK_PI(2const) situation πŸŽ€βœ¨

πŸ“¦ 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