]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/futex.2
futex.2: Add introductory paragraph describing 'timeout', 'uaddr2', and 'val3'
[thirdparty/man-pages.git] / man2 / futex.2
CommitLineData
8f0aff2a 1.\" Page by b.hubert
2297bf0e 2.\"
2e46a6e7 3.\" %%%LICENSE_START(FREELY_REDISTRIBUTABLE)
8f0aff2a 4.\" may be freely modified and distributed
8ff7380d 5.\" %%%LICENSE_END
fea681da
MK
6.\"
7.\" Niki A. Rahimi (LTC Security Development, narahimi@us.ibm.com)
8.\" added ERRORS section.
9.\"
10.\" Modified 2004-06-17 mtk
11.\" Modified 2004-10-07 aeb, added FUTEX_REQUEUE, FUTEX_CMP_REQUEUE
12.\"
c13182ef
MK
13.\" 2.6.18 adds (Ingo Molnar) priority inheritance support:
14.\" FUTEX_LOCK_PI, FUTEX_UNLOCK_PI, and FUTEX_TRYLOCK_PI. These need
34f7665a
MK
15.\" to be documented in the manual page. Probably there is sufficient
16.\" material in the kernel source file Documentation/pi-futex.txt.
4f58b197
MK
17.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
18.\" Author: Ingo Molnar <mingo@elte.hu>
19.\" Date: Tue Jun 27 02:54:58 2006 -0700
20.\"
21.\" commit e2970f2fb6950183a34e8545faa093eb49d186e1
22.\" Author: Ingo Molnar <mingo@elte.hu>
23.\" Date: Tue Jun 27 02:54:47 2006 -0700
24.\"
27b38e1c 25.\" See Documentation/pi-futex.txt
4f58b197 26.\"
bea08fec 27.\" FIXME .
40d5cf23 28.\" 2.6.25 adds FUTEX_WAKE_BITSET, FUTEX_WAIT_BITSET
4f58b197
MK
29.\" commit cd689985cf49f6ff5c8eddc48d98b9d581d9475d
30.\" Author: Thomas Gleixner <tglx@linutronix.de>
31.\" Date: Fri Feb 1 17:45:14 2008 +0100
32.\"
bea08fec 33.\" FIXME .
4f58b197
MK
34.\" 2.6.31 adds FUTEX_WAIT_REQUEUE_PI, FUTEX_CMP_REQUEUE_PI
35.\" commit 52400ba946759af28442dee6265c5c0180ac7122
36.\" Author: Darren Hart <dvhltc@us.ibm.com>
37.\" Date: Fri Apr 3 13:40:49 2009 -0700
38.\"
39.\" commit ba9c22f2c01cf5c88beed5a6b9e07d42e10bd358
40.\" Author: Darren Hart <dvhltc@us.ibm.com>
41.\" Date: Mon Apr 20 22:22:22 2009 -0700
42.\"
43.\" See Documentation/futex-requeue-pi.txt
34f7665a 44.\"
3d155313 45.TH FUTEX 2 2014-05-21 "Linux" "Linux Programmer's Manual"
fea681da 46.SH NAME
ce154705 47futex \- fast user-space locking
fea681da 48.SH SYNOPSIS
9d9dc1e8 49.nf
fea681da
MK
50.sp
51.B "#include <linux/futex.h>"
fea681da
MK
52.B "#include <sys/time.h>"
53.sp
d33602c4
MK
54.BI "int futex(int *" uaddr ", int " futex_op ", int " val ,
55.BI " const struct timespec *" timeout ,
9d9dc1e8 56.BI " int *" uaddr2 ", int " val3 );
fea681da 57.\" int *? void *? u32 *?
9d9dc1e8 58.fi
409f08b0 59
b939d6e4
MK
60.IR Note :
61There is no glibc wrapper for this system call; see NOTES.
47297adb 62.SH DESCRIPTION
fea681da
MK
63.PP
64The
e511ffb6 65.BR futex ()
fea681da
MK
66system call provides a method for
67a program to wait for a value at a given address to change, and a
68method to wake up anyone waiting on a particular address (while the
69addresses for the same memory in separate processes may not be
70equal, the kernel maps them internally so the same memory mapped in
71different locations will correspond for
e511ffb6 72.BR futex ()
c13182ef 73calls).
fd3fa7ef 74This system call is typically used to
fea681da
MK
75implement the contended case of a lock in shared memory, as
76described in
a8bda636 77.BR futex (7).
fea681da 78.PP
f388ba70
MK
79When a futex operation did not finish uncontended in user space, a
80.BR futex ()
81call needs to be made to the kernel to arbitrate.
c13182ef 82Arbitration can either mean putting the calling
fea681da
MK
83process to sleep or, conversely, waking a waiting process.
84.PP
f388ba70
MK
85Callers of
86.BR futex ()
87are expected to adhere to the semantics described in
a8bda636 88.BR futex (7).
fea681da 89As these
d603cc27 90semantics involve writing nonportable assembly instructions, this in turn
fea681da
MK
91probably means that most users will in fact be library authors and not
92general application developers.
93.PP
94The
95.I uaddr
f388ba70
MK
96argument points to an integer which stores the counter (futex).
97On all platforms, futexes are four-byte integers that
98must be aligned on a four-byte boundary.
99The operation to perform on the futex is specified in the
100.I futex_op
101argument;
102.IR val
103is a value whose meaning and purpose depends on
104.IR futex_op .
36ab2074
MK
105
106The remaining arguments
107.RI ( timeout ,
108.IR uaddr2 ,
109and
110.IR val3 )
111are required only for certain of the futex operations described below.
112Where one of these arguments is not required, it is ignored.
113For several blocking operations, the
114.I timeout
115argument is a pointer to a
116.IR timespec
117structure that specifies a timeout for the operation.
118However, notwithstanding the prototype shown above, for some operations,
119this argument is instead a four-byte integer whose meaning
120is determined by the operation.
121Where it is required,
122.IR uaddr2
123is a pointer to a second futex that is employed by the operation.
124The interpretation of the final integer argument,
125.IR val3 ,
126depends on the operation.
127
6be4bad7 128The
d33602c4 129.I futex_op
6be4bad7
MK
130argument consists of two parts:
131a command that specifies the operation to be performed,
132bit-wise ORed with zero or or more options that
133modify the behaviour of the operation.
fc30eb79 134The options that may be included in
d33602c4 135.I futex_op
fc30eb79
TG
136are as follows:
137.TP
138.BR FUTEX_PRIVATE_FLAG " (since Linux 2.6.22)"
139.\" commit 34f01cc1f512fa783302982776895c73714ebbc2
140This option bit can be employed with all futex operations.
141It tells the kernel that the futex is process private and not shared
142with another process.
143This allows the kernel to choose the fast path for validating
144the user-space address and avoids expensive VMA lookups,
145taking reference counts on file backing store, and so on.
2e98bbc2
TG
146.TP
147.BR FUTEX_CLOCK_REALTIME " (since Linux 2.6.28)"
148.\" commit 1acdac104668a0834cfa267de9946fac7764d486
4a7e5b05 149This option bit can be employed only with the
2e98bbc2
TG
150.BR FUTEX_WAIT_BITSET
151and
152.BR FUTEX_WAIT_REQUEUE_PI
153operations (described below).
154
155If this option is set,
156the kernel treats the user space supplied timeout as an absolute
157time based on
158.BR CLOCK_REALTIME .
159
160If this option is not set,
1c952cf5
MK
161the kernel treats the user space supplied timeout as relative time,
162.\" FIXME I added CLOCK_MONOTONIC here. Is it correct?
163measured against the
164.BR CLOCK_MONOTONIC
165clock.
6be4bad7
MK
166.PP
167The operation specified in
d33602c4 168.I futex_op
6be4bad7 169is one of the following:
fea681da 170.TP
81c9d87e
MK
171.BR FUTEX_WAIT " (since Linux 2.6.0)"
172.\" Strictly speaking, since some time in 2.5.x
f065673c
MK
173This operation tests that the value at the
174location pointed to by the futex address
fea681da
MK
175.I uaddr
176still contains the value
177.IR val ,
f065673c 178and then sleeps awaiting
682edefb 179.B FUTEX_WAKE
f065673c
MK
180on the futex address.
181The test and sleep steps are performed atomically.
182If the futex value does not match
183.IR val ,
184then the call returns immediately with the error
185.BR EWOULDBLOCK .
186.\" FIXME I added the following sentence. Please confirm that it is correct.
187The purpose of the test step is to detect races where
188another process changes that value of the futex between
189the time it was last checked and the time of the
190.BR FUTEX_WAIT
191oepration.
192
1909e523 193
c13182ef 194If the
fea681da 195.I timeout
1c952cf5
MK
196argument is non-NULL, its contents specify a relative timeout for the wait
197.\" FIXME I added CLOCK_MONOTONIC here. Is it correct?
198measured according to the
199.BR CLOCK_MONOTONIC
200clock.
82a6092b
MK
201(This interval will be rounded up to the system clock granularity,
202and kernel scheduling delays mean that the
203blocking interval may overrun by a small amount.)
204If
205.I timeout
206is NULL, the call blocks indefinitely.
4798a7f3 207
c13182ef 208The arguments
fea681da
MK
209.I uaddr2
210and
211.I val3
212are ignored.
213
214For
a8bda636 215.BR futex (7),
fea681da
MK
216this call is executed if decrementing the count gave a negative value
217(indicating contention), and will sleep until another process releases
682edefb
MK
218the futex and executes the
219.B FUTEX_WAKE
220operation.
fea681da 221.TP
d67e21f5
MK
222.BR FUTEX_WAIT_BITSET " (since Linux 2.6.25)"
223.\" commit cd689985cf49f6ff5c8eddc48d98b9d581d9475d
224.\" FIXME TO complete
225[As yet undocumented]
226.TP
81c9d87e
MK
227.BR FUTEX_WAKE " (since Linux 2.6.0)"
228.\" Strictly speaking, since Linux 2.5.x
f065673c
MK
229This operation wakes at most
230.I val
231processes waiting (i.e., inside
232.BR FUTEX_WAIT )
233on the futex at the address
234.IR uaddr .
235Most commonly,
236.I val
237is specified as either 1 (wake up a single waiter) or
238.BR INT_MAX
239(wake up all waiters).
4798a7f3 240
fea681da
MK
241The arguments
242.IR timeout ,
243.I uaddr2
244and
245.I val3
246are ignored.
247
248For
a8bda636 249.BR futex (7),
fea681da
MK
250this is executed if incrementing
251the count showed that there were waiters, once the futex value has been set
252to 1 (indicating that it is available).
6bac3b85
MK
253.\"
254.\" FIXME I added some FUTEX_WAKE_OP text, and I'd be happy if someone
255.\" checked it.
fea681da 256.TP
d67e21f5
MK
257.BR FUTEX_WAKE_OP " (since Linux 2.6.14)"
258.\" commit 4732efbeb997189d9f9b04708dc26bf8613ed721
6bac3b85
MK
259.\" Author: Jakub Jelinek <jakub@redhat.com>
260.\" Date: Tue Sep 6 15:16:25 2005 -0700
261This operation was added to support some user-space use cases
262where more than one futex must be handled at the same time.
263The most notable example is the implementation of
264.BR pthread_cond_signal (3),
265which requires operations on two futexes,
266the one used to implement the mutex and the one used in the implementation
267of the wait queue associated with the condition variable.
268.BR FUTEX_WAKE_OP
269allows such cases to be implemented without leading to
270high rates of contention and context switching.
271
272The
273.BR FUTEX_WAIT_OP
274operation is equivalent to atomically executing the following code:
275
276.in +4n
277.nf
278int oldval = *(int *) uaddr2;
279*(int *) uaddr2 = oldval \fIop\fP \fIoparg\fP;
280futex(uaddr, FUTEX_WAKE, val, 0, 0, 0);
281if (oldval \fIcmp\fP \fIcmparg\fP)
282 futex(uaddr2, FUTEX_WAKE, nr_wake2, 0, 0, 0);
283.fi
284.in
285
286In other words,
287.BR FUTEX_WAIT_OP
288does the following:
289.RS
290.IP * 3
291saves the original value of the futex at
292.IR uaddr2 ;
293.IP *
294performs an operation to modify the value of the futex at
295.IR uaddr2 ;
296.IP *
297wakes up a maximum of
298.I val
299waiters on the futex
300.IR uaddr ;
301and
302.IP *
303dependent on the results of a test of the original value of the futex at
304.IR uaddr2 ,
305wakes up a maximum of
306.I nr_wake2
307waiters on the futex
308.IR uaddr2 .
309.RE
310.IP
311The
312.I nr_wake2
313value is actually the
314.BR futex ()
315.I timeout
316argument (ab)used to specify how many of the waiters on the futex at
317.IR uaddr2
318are to be woken up;
319the kernel casts the
320.I timeout
321value to
322.IR u32 .
323
324The operation and comparison that are to be performed are encoded
325in the bits of the argument
326.IR val3 .
327Pictorially, the encoding is:
328
329.in +4n
330.nf
331 +-----+-----+---------------+---------------+
332 | op | cmp | oparg | cmparg |
333 +-----+-----+---------------+---------------+
334# of bits: 4 4 12 12
335
336.fi
337.in
338
339Expressed in code, the encoding is:
340
341.in +4n
342.nf
343#define FUTEX_OP(op, oparg, cmp, cmparg) \\
344 (((op & 0xf) << 28) | \\
345 ((cmp & 0xf) << 24) | \\
346 ((oparg & 0xfff) << 12) | \\
347 (cmparg & 0xfff))
348.fi
349.in
350
351In the above,
352.I op
353and
354.I cmp
355are each one of the codes listed below.
356The
357.I oparg
358and
359.I cmparg
360components are literal numeric values, except as noted below.
361
362The
363.I op
364component has one of the following values:
365
366.in +4n
367.nf
368FUTEX_OP_SET 0 /* uaddr2 = oparg; */
369FUTEX_OP_ADD 1 /* uaddr2 += oparg; */
370FUTEX_OP_OR 2 /* uaddr2 |= oparg; */
371FUTEX_OP_ANDN 3 /* uaddr2 &= ~oparg; */
372FUTEX_OP_XOR 4 /* uaddr2 ^= oparg; */
373.fi
374.in
375
376In addition, bit-wise ORing the following value into
377.I op
378causes
379.IR "(1\ <<\ oparg)"
380to be used as the operand:
381
382.in +4n
383.nf
384FUTEX_OP_ARG_SHIFT 8 /* Use (1 << oparg) as operand */
385.fi
386.in
387
388The
389.I cmp
390field is one of the following:
391
392.in +4n
393.nf
394FUTEX_OP_CMP_EQ 0 /* if (oldval == cmparg) wake */
395FUTEX_OP_CMP_NE 1 /* if (oldval != cmparg) wake */
396FUTEX_OP_CMP_LT 2 /* if (oldval < cmparg) wake */
397FUTEX_OP_CMP_LE 3 /* if (oldval <= cmparg) wake */
398FUTEX_OP_CMP_GT 4 /* if (oldval > cmparg) wake */
399FUTEX_OP_CMP_GE 5 /* if (oldval >= cmparg) wake */
400.fi
401.in
402
403The return value of
404.BR FUTEX_WAKE_OP
405is the sum of the number of waiters woken on the futex
406.IR uaddr
407plus the number of waiters woken on the futex
408.IR uaddr2 .
d67e21f5
MK
409.TP
410.BR FUTEX_WAKE_BITSET " (since Linux 2.6.25)"
411.\" commit cd689985cf49f6ff5c8eddc48d98b9d581d9475d
412.\" FIXME TO complete
413[As yet undocumented]
414.TP
415.BR FUTEX_LOCK_PI " (since Linux 2.6.18)"
416.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
417.\" FIXME to complete
418[As yet undocumented]
419.TP
420.BR FUTEX_UNLOCK_PI " (since Linux 2.6.18)"
421.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
422.\" FIXME to complete
423[As yet undocumented]
424.TP
425.BR FUTEX_TRYLOCK_PI " (since Linux 2.6.18)"
426.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
427.\" FIXME to complete
428[As yet undocumented]
429.TP
81c9d87e
MK
430.BR FUTEX_FD " (from Linux 2.6.0 up to and including Linux 2.6.25)"
431.\" Strictly speaking, from Linux 2.5.x to 2.6.25
fea681da
MK
432To support asynchronous wakeups, this operation associates a file descriptor
433with a futex.
434.\" , suitable for .BR poll (2).
682edefb
MK
435If another process executes a
436.BR FUTEX_WAKE ,
437the process will receive the signal number that was passed in
fea681da
MK
438.IR val .
439The calling process must close the returned file descriptor after use.
4798a7f3 440
fea681da
MK
441The arguments
442.IR timeout ,
443.I uaddr2
444and
445.I val3
446are ignored.
447
c13182ef 448To prevent race conditions, the caller should test if the futex has
682edefb
MK
449been upped after
450.B FUTEX_FD
451returns.
266a5e91 452
da36351e 453Because it was inherently racy,
682edefb 454.B FUTEX_FD
5fab2e7c 455has been removed from Linux 2.6.26 onward.
fea681da 456.TP
81c9d87e
MK
457.BR FUTEX_REQUEUE " (since Linux 2.6.0)"
458.\" Strictly speaking: from Linux 2.5.70
4ac63a6c
MK
459.\"
460.\" FIXME I added this warning. Okay?
461.IR "Avoid using this operation" .
dd05d612 462It is broken (unavoidably racy) for its intended purpose.
4ac63a6c
MK
463Use
464.BR FUTEX_CMP_REQUEUE
465instead.
466
dd05d612
MK
467This operation performs the same task as
468.BR FUTEX_CMP_REQUEUE ,
469except that no check is made using the value in
470.IR val3 .
471(The argument
fea681da 472.I val3
dd05d612 473is ignored.)
fea681da
MK
474.TP
475.BR FUTEX_CMP_REQUEUE " (since Linux 2.6.7)"
3dfcc11d 476This operation was added as a replacement for the earlier
682edefb 477.BR FUTEX_REQUEUE ,
3dfcc11d
MK
478because that operation was racy for its intended use.
479
480As with
682edefb 481.BR FUTEX_REQUEUE ,
3dfcc11d
MK
482the
483.BR FUTEX_CMP_REQUEUE
484operation is used to avoid a "thundering herd" effect when
485.B FUTEX_WAKE
486is used and all processes woken up need to acquire another futex.
487It differs from
488.BR FUTEX_REQUEUE
489in that it first checks whether the location
fea681da
MK
490.I uaddr
491still contains the value
492.IR val3 .
e808bba0
MK
493If not, the operation fails with the error
494.BR EAGAIN .
3dfcc11d
MK
495.\" FIXME I added the following sentence on rational for FUTEX_CMP_REQUEUE.
496.\" Is it correct? SHould it be expanded?
497This additional feature of
498.BR FUTEX_CMP_REQUEUE
499can be used by the caller to (atomically) detect changes
500in the value of the target futex at
501.IR uaddr2 .
4798a7f3 502
3dfcc11d
MK
503The operation wakes up a maximum of
504.I val
505waiters that are waiting on the futex at
506.IR uaddr .
507If there are more than
508.I val
509waiters, then the remaining waiters are removed
510from the wait queue of the source futex at
511.I uaddr
512and added to the wait queue of the target futex at
513.IR uaddr2 .
514The
515.I timeout
516argument is (ab)used to specify a cap on the number of waiters
517that are requeued to the futex at
518.IR uaddr2 ;
519the kernel casts the
fea681da 520.I timeout
3dfcc11d
MK
521value to
522.IR u32 .
523
524.\" FIXME Please review the following new paragraph to see if it is
525.\" accurate.
526Typical values to specify for
527.I val
528are 0 or or 1.
529(Specifying
530.BR INT_MAX
531is not useful, because it would make the
532.BR FUTEX_CMP_REQUEUE
533operation equivalent to
534.BR FUTEX_WAKE .)
535The cap value specified via the (abused)
536.I timeout
537argument is typically either 1 or
538.BR INT_MAX .
539(Specifying the argument as 0 is not useful, because it would make the
540.BR FUTEX_CMP_REQUEUE
541operation equivalent to
542.BR FUTEX_WAIT .)
d67e21f5
MK
543.TP
544.BR FUTEX_CMP_REQUEUE_PI " (since Linux 2.6.31)"
545.\" commit 52400ba946759af28442dee6265c5c0180ac7122
546.\" FIXME to complete
547[As yet undocumented]
548.TP
549.BR FUTEX_WAIT_REQUEUE_PI " (since Linux 2.6.31)"
550.\" commit 52400ba946759af28442dee6265c5c0180ac7122
551.\" FIXME to complete
552[As yet undocumented]
47297adb 553.SH RETURN VALUE
fea681da 554.PP
e808bba0
MK
555In the event of an error, all operations return \-1, and set
556.I errno
557to indicate the error.
558The return value on success depends on the operation,
559as described in the following list:
fea681da
MK
560.TP
561.B FUTEX_WAIT
682edefb
MK
562Returns 0 if the process was woken by a
563.B FUTEX_WAKE
564call.
e808bba0 565See ERRORS for the various possible error returns.
fea681da
MK
566.TP
567.B FUTEX_WAKE
568Returns the number of processes woken up.
569.TP
570.B FUTEX_FD
571Returns the new file descriptor associated with the futex.
572.TP
573.B FUTEX_REQUEUE
574Returns the number of processes woken up.
575.TP
576.B FUTEX_CMP_REQUEUE
3dfcc11d
MK
577Returns the total number of processes woken up or requeued to the futex at
578.IR uaddr2 .
579If this value is greater than
580.IR val ,
581then difference is the number of waiters requeued to the futex at
582.IR uaddr2 .
519f2c3d
MK
583.\"
584.\" FIXME Add success returns for other operations
fea681da
MK
585.SH ERRORS
586.TP
587.B EACCES
588No read access to futex memory.
589.TP
590.B EAGAIN
682edefb 591.B FUTEX_CMP_REQUEUE
e808bba0 592detected that the value pointed to by
9f6c40c0
МК
593.I uaddr
594is not equal to the expected value
595.IR val3 .
fd1dc4c2 596.\" FIXME: Is the following sentence correct?
fea681da 597(This probably indicates a race;
682edefb
MK
598use the safe
599.B FUTEX_WAKE
600now.)
fea681da
MK
601.TP
602.B EFAULT
1ea901e8
MK
603A required pointer argument (i.e.,
604.IR uaddr ,
605.IR uaddr2 ,
606or
607.IR timeout )
496df304 608did not point to a valid user-space address.
fea681da 609.TP
9f6c40c0 610.B EINTR
e808bba0 611A
9f6c40c0 612.B FUTEX_WAIT
e808bba0
MK
613operation was interrupted by a signal (see
614.BR signal (7))
615or a spurious wakeup.
9f6c40c0 616.TP
fea681da 617.B EINVAL
fb2f4c27
MK
618.RB ( FUTEX_WAIT ,
619.BR FUTEX_WAIT_REQUEUE_PI )
620The supplied
621.I timeout
622argument was invalid
623.RI ( tv_sec
624was less than zero, or
625.IR tv_nsec
626was not less than 1000,000,000).
627.TP
628.B EINVAL
ea355b7f 629.RB ( FUTEX_WAIT ,
caf1ff25 630.BR FUTEX_WAKE ,
6bac3b85 631.BR FUTEX_WAKE_OP ,
a1f47699
MK
632.BR FUTEX_REQUEUE ,
633.BR FUTEX_CMP_REQUEUE )
51ee94be 634.I uaddr
caf1ff25 635or (for
a1f47699
MK
636.BR FUTEX_REQUEUE
637and
638.BR FUTEX_CMP_REQUEUE )
caf1ff25 639.I uaddr2
51ee94be
MK
640does not point to a valid object\(emthat is,
641the address is not 4-byte-aligned.
642.TP
643.B EINVAL
bae14b6c 644.RB ( FUTEX_WAKE ,
e169277f
MK
645.BR FUTEX_REQUEUE ,
646.BR FUTEX_CMP_REQUEUE )
496df304 647The kernel detected an inconsistency between the user-space state at
9534086b
TG
648.I uaddr
649and the kernel state\(emthat is, it detected a waiter which waits in
650.BR FUTEX_LOCK_PI .
651.TP
652.B EINVAL
add875c0
MK
653.RB ( FUTEX_REQUEUE )
654.\" FIXME tglx suggested adding this, but does this error really
655.\" occur for FUTEX_REQUEUE?
656.I uaddr
657equals
658.IR uaddr2
659(i.e., an attempt was made to requeue to the same futex).
660.TP
661.B EINVAL
6bac3b85
MK
662.RB ( FUTEX_WAKE_OP )
663The kernel detected an inconsistency between the user-space state at
664.I uaddr
665and the kernel state; that is, it detected a waiter which waits in
666.B FUTEX_LOCK_PI
667on
668.IR uaddr .
669.TP
670.B EINVAL
4832b48a 671Invalid argument.
fea681da
MK
672.TP
673.B ENFILE
674The system limit on the total number of open files has been reached.
4701fc28
MK
675.TP
676.B ENOSYS
677Invalid operation specified in
d33602c4 678.IR futex_op .
9f6c40c0 679.TP
4a7e5b05
MK
680.B ENOSYS
681The
682.BR FUTEX_CLOCK_REALTIME
683option was specified in
d33602c4 684.I futex_op ,
4a7e5b05
MK
685but the accompanying operation was neither
686.BR FUTEX_WAIT_BITSET
687nor
688.BR FUTEX_WAIT_REQUEUE_PI .
689.TP
9f6c40c0 690.B ETIMEDOUT
d1926d78
MK
691.RB ( FUTEX_WAIT )
692The operation timed out.
9f6c40c0
МК
693.TP
694.B EWOULDBLOCK
d33602c4 695.I futex_op
e808bba0
MK
696was
697.BR FUTEX_WAIT
698and the value pointed to by
9f6c40c0
МК
699.I uaddr
700was not equal to the expected value
701.I val
e808bba0 702at the time of the call.
47297adb 703.SH VERSIONS
a1d5f77c 704.PP
81c9d87e
MK
705Futexes were first made available in a stable kernel release
706with Linux 2.6.0.
707
a1d5f77c
MK
708Initial futex support was merged in Linux 2.5.7 but with different semantics
709from what was described above.
c4bb193f 710A 4-argument system call with the semantics
fd3fa7ef 711described in this page was introduced in Linux 2.5.40.
11b520ed 712In Linux 2.5.70, one argument
a1d5f77c 713was added.
11b520ed 714In Linux 2.6.7, a sixth argument was added\(emmessy, especially
a1d5f77c 715on the s390 architecture.
47297adb 716.SH CONFORMING TO
8382f16d 717This system call is Linux-specific.
47297adb 718.SH NOTES
fea681da 719.PP
fcdad7d6 720To reiterate, bare futexes are not intended as an easy-to-use abstraction
c13182ef 721for end-users.
fcdad7d6 722(There is no wrapper function for this system call in glibc.)
c13182ef 723Implementors are expected to be assembly literate and to have
7fac88a9 724read the sources of the futex user-space library referenced below.
d282bb24 725.\" .SH AUTHORS
fea681da
MK
726.\" .PP
727.\" Futexes were designed and worked on by
728.\" Hubertus Franke (IBM Thomas J. Watson Research Center),
729.\" Matthew Kirkwood, Ingo Molnar (Red Hat)
730.\" and Rusty Russell (IBM Linux Technology Center).
731.\" This page written by bert hubert.
47297adb 732.SH SEE ALSO
d806bc05 733.BR restart_syscall (2),
14d8dd3b 734.BR futex (7)
fea681da 735.PP
52087dd3 736\fIFuss, Futexes and Furwocks: Fast Userlevel Locking in Linux\fP
9b936e9e
MK
737(proceedings of the Ottawa Linux Symposium 2002), online at
738.br
608bf950
SK
739.UR http://kernel.org\:/doc\:/ols\:/2002\:/ols2002-pages-479-495.pdf
740.UE
f42eb21b
MK
741
742\fIFutexes Are Tricky\fP (updated in 2011), Ulrich Drepper
743.UR http://www.akkadia.org/drepper/futex.pdf
744.UE
9b936e9e
MK
745.PP
746Futex example library, futex-*.tar.bz2 at
747.br
a605264d 748.UR ftp://ftp.kernel.org\:/pub\:/linux\:/kernel\:/people\:/rusty/
608bf950 749.UE