| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" %%%LICENSE_START(FREELY_REDISTRIBUTABLE) |
| 4 |
.\" may be freely modified and distributed |
| 5 |
.\" %%%LICENSE_END |
| 6 |
.\" |
| 7 |
.TH FUTEX_TRYLOCK_PI 2const 2025-09-21 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
FUTEX_TRYLOCK_PI \- try to lock a priority-inheritance futex |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.BR "#include <linux/futex.h>" " /* Definition of " FUTEX_* " constants */" |
| 16 |
.BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */" |
| 17 |
.B #include <unistd.h> |
| 18 |
.P |
| 19 |
.BI "long syscall(SYS_futex, uint32_t *" uaddr ", FUTEX_TRYLOCK_PI);" |
| 20 |
.fi |
| 21 |
.SH DESCRIPTION |
| 22 |
This operation tries to acquire the lock at |
| 23 |
.IR uaddr . |
| 24 |
It is invoked when a user-space atomic acquire did not |
| 25 |
succeed because the futex word was not 0. |
| 26 |
.P |
| 27 |
Because the kernel has access to more state information than user space, |
| 28 |
acquisition of the lock might succeed if performed by the |
| 29 |
kernel in cases where the futex word |
| 30 |
(i.e., the state information accessible to use-space) contains stale state |
| 31 |
.RB ( FUTEX_WAITERS |
| 32 |
and/or |
| 33 |
.BR FUTEX_OWNER_DIED ). |
| 34 |
This can happen when the owner of the futex died. |
| 35 |
User space cannot handle this condition in a race-free manner, |
| 36 |
but the kernel can fix this up and acquire the futex. |
| 37 |
.\" Paraphrasing a f2f conversation with Thomas Gleixner about the |
| 38 |
.\" above point (Aug 2015): ### |
| 39 |
.\" There is a rare possibility of a race condition involving an |
| 40 |
.\" uncontended futex with no owner, but with waiters. The |
| 41 |
.\" kernel-user-space contract is that if a futex is nonzero, you must |
| 42 |
.\" go into kernel. The futex was owned by a task, and that task dies |
| 43 |
.\" but there are no waiters, so the futex value is non zero. |
| 44 |
.\" Therefore, the next locker has to go into the kernel, |
| 45 |
.\" so that the kernel has a chance to clean up. (CMXCH on zero |
| 46 |
.\" in user space would fail, so kernel has to clean up.) |
| 47 |
.\" Darren Hart (Oct 2015): |
| 48 |
.\" The trylock in the kernel has more state, so it can independently |
| 49 |
.\" verify the flags that user space must trust implicitly. |
| 50 |
.\" |
| 51 |
.SH RETURN VALUE |
| 52 |
On error, |
| 53 |
\-1 is returned, |
| 54 |
and |
| 55 |
.I errno |
| 56 |
is set to indicate the error. |
| 57 |
.P |
| 58 |
On success, |
| 59 |
.B FUTEX_TRYLOCK_PI |
| 60 |
Returns 0 if the futex was successfully locked. |
| 61 |
.SH ERRORS |
| 62 |
See |
| 63 |
.BR futex (2). |
| 64 |
.TP |
| 65 |
.B EAGAIN |
| 66 |
The futex owner thread ID of |
| 67 |
.I uaddr |
| 68 |
is about to exit, |
| 69 |
but has not yet handled the internal state cleanup. |
| 70 |
Try again. |
| 71 |
.TP |
| 72 |
.B EDEADLK |
| 73 |
The futex word at |
| 74 |
.I uaddr |
| 75 |
is already locked by the caller. |
| 76 |
.TP |
| 77 |
.B EINVAL |
| 78 |
The kernel detected an inconsistency between the user-space state at |
| 79 |
.I uaddr |
| 80 |
and the kernel state. |
| 81 |
This indicates either state corruption |
| 82 |
or that the kernel found a waiter on |
| 83 |
.I uaddr |
| 84 |
which is waiting via |
| 85 |
.BR FUTEX_WAIT (2const) |
| 86 |
or |
| 87 |
.BR FUTEX_WAIT_BITSET (2const). |
| 88 |
.TP |
| 89 |
.B ENOMEM |
| 90 |
The kernel could not allocate memory to hold state information. |
| 91 |
.TP |
| 92 |
.B ENOSYS |
| 93 |
A run-time check determined that the operation is not available. |
| 94 |
The PI-futex operations are not implemented on all architectures and |
| 95 |
are not supported on some CPU variants. |
| 96 |
.TP |
| 97 |
.B EPERM |
| 98 |
The caller is not allowed to attach itself to the futex at |
| 99 |
.IR uaddr . |
| 100 |
(This may be caused by a state corruption in user space.) |
| 101 |
.TP |
| 102 |
.B ESRCH |
| 103 |
The thread ID in the futex word at |
| 104 |
.I uaddr |
| 105 |
does not exist. |
| 106 |
.SH STANDARDS |
| 107 |
Linux. |
| 108 |
.SH HISTORY |
| 109 |
Linux 2.6.18. |
| 110 |
.\" commit c87e2837be82df479a6bae9f155c43516d2feebc |
| 111 |
.SH SEE ALSO |
| 112 |
.BR futex (2) |