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 ofuaddris about to exit, but hasn't handled the internal state cleanup yet. Try again, bestie.EDEADLKβ the futex word atuaddris already locked by the caller. yes, by you. awkward πEINVALβ the kernel detected an inconsistency between the user-space state atuaddrand the kernel state. This means either state corruption, or the kernel found a waiter onuaddrthat's waiting viaFUTEX_WAIT(2const)orFUTEX_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 atuaddr. (This may be caused by a state corruption in user space.)ESRCHβ the thread ID in the futex word atuaddrdoes not exist. ghost thread π»
π STANDARDS π
Linux.
β HISTORY β
Linux 2.6.18.
π₯ SEE ALSO π₯
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