]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/futex.2
futex.2: wfix
[thirdparty/man-pages.git] / man2 / futex.2
CommitLineData
8f0aff2a 1.\" Page by b.hubert
1abce893
MK
2.\" and Copyright (C) 2015, Thomas Gleixner <tglx@linutronix.de>
3.\" and Copyright (C) 2015, Michael Kerrisk <mtk.manpages@gmail.com>
2297bf0e 4.\"
2e46a6e7 5.\" %%%LICENSE_START(FREELY_REDISTRIBUTABLE)
8f0aff2a 6.\" may be freely modified and distributed
8ff7380d 7.\" %%%LICENSE_END
fea681da
MK
8.\"
9.\" Niki A. Rahimi (LTC Security Development, narahimi@us.ibm.com)
10.\" added ERRORS section.
11.\"
12.\" Modified 2004-06-17 mtk
13.\" Modified 2004-10-07 aeb, added FUTEX_REQUEUE, FUTEX_CMP_REQUEUE
14.\"
47f5c4ba
MK
15.\" FIXME Still to integrate are some points from Torvald Riegel's mail of
16.\" 2015-01-23:
17.\" http://thread.gmane.org/gmane.linux.kernel/1703405/focus=7977
18.\"
78e85692 19.\" FIXME Do we need to add some text regarding Torvald Riegel's 2015-01-24 mail
02182e7c
MK
20.\" at http://thread.gmane.org/gmane.linux.kernel/1703405/focus=1873242
21.\"
3d155313 22.TH FUTEX 2 2014-05-21 "Linux" "Linux Programmer's Manual"
fea681da 23.SH NAME
ce154705 24futex \- fast user-space locking
fea681da 25.SH SYNOPSIS
9d9dc1e8 26.nf
fea681da
MK
27.sp
28.B "#include <linux/futex.h>"
fea681da
MK
29.B "#include <sys/time.h>"
30.sp
d33602c4 31.BI "int futex(int *" uaddr ", int " futex_op ", int " val ,
768d3c23 32.BI " const struct timespec *" timeout , \
c6dc40a2 33" \fR /* or: \fBuint32_t \fIval2\fP */
9d9dc1e8 34.BI " int *" uaddr2 ", int " val3 );
9d9dc1e8 35.fi
409f08b0 36
b939d6e4
MK
37.IR Note :
38There is no glibc wrapper for this system call; see NOTES.
47297adb 39.SH DESCRIPTION
fea681da
MK
40.PP
41The
e511ffb6 42.BR futex ()
4b35dc5d 43system call provides a method for waiting until a certain condition becomes
077981d4
MK
44true.
45It is typically used as a blocking construct in the context of
4c8cb0ff 46shared-memory synchronization: The program implements the majority of
594536fb 47the synchronization in user space, and uses one of the operations of
4c8cb0ff
MK
48the system call when it is likely that it has to block for
49a longer time until the condition becomes true.
077981d4 50The program uses another operation of the system call to wake
4b35dc5d
TR
51anyone waiting for a particular condition.
52
4c8cb0ff
MK
53The condition is represented by the futex word, which is an address
54in memory supplied to the
4b35dc5d 55.BR futex ()
a5c5a06a 56system call, and the 32-bit value at this memory location.
344df366
HS
57(While the virtual addresses for the same physical memory address
58in separate processes may be different,
59the same physical address may be shared by the processes using
60.BR mmap (2).)
809ca3ae 61
0c3ec26b
MK
62When executing a futex operation that requests to block a thread,
63the kernel will block only if the futex word has the value that the
4c8cb0ff 64calling thread supplied as expected value.
077981d4
MK
65The load from the futex word, the comparison with
66the expected value,
67and the actual blocking will happen atomically and totally
0c3ec26b 68ordered with respect to concurrently executing futex
b80daba2
HS
69operations on the same futex word.
70Thus, the futex word is used to connect the synchronization in user space
4c8cb0ff 71with the implementation of blocking by the kernel; similar to an atomic
4b35dc5d 72compare-and-exchange operation that potentially changes shared memory,
077981d4 73blocking via a futex is an atomic compare-and-block operation.
d6bb5a38
MK
74.\" FIXME(Torvald Riegel):
75.\" Eventually we want to have some text in NOTES to satisfy
76.\" the reference in the following sentence
77.\" See NOTES for
78.\" a detailed specification of the synchronization semantics.
4b35dc5d 79
077981d4
MK
80One example use of futexes is implementing locks.
81The state of the lock (i.e.,
4c8cb0ff
MK
82acquired or not acquired) can be represented as an atomically accessed
83flag in shared memory.
84In the uncontended case,
85a thread can access or modify the lock state with atomic instructions,
86for example atomically changing it from not acquired to acquired
87using an atomic compare-and-exchange instruction.
36a90a75 88A thread may be unable to acquire a lock because
8e754e12
HS
89it is already acquired by another thread.
90It then may pass the lock's flag as futex word and the value
0c3ec26b 91representing the acquired state as the expected value to a
8e754e12
HS
92.BR futex ()
93wait operation.
0c3ec26b 94The call to
8e754e12
HS
95.BR futex ()
96will block if and only if the lock is still acquired.
077981d4 97When releasing the lock, a thread has to first reset the
0c3ec26b 98lock state to not acquired and then execute a futex
d725ab77 99operation that wakes threads blocked on the lock flag used as futex word
4c8cb0ff 100(this can be be further optimized to avoid unnecessary wake-ups).
077981d4 101See
4b35dc5d
TR
102.BR futex (7)
103for more detail on how to use futexes.
104
105Besides the basic wait and wake-up futex functionality, there are further
077981d4
MK
106futex operations aimed at supporting more complex use cases.
107Also note that
4c8cb0ff
MK
108no explicit initialization or destruction are necessary to use futexes;
109the kernel maintains a futex
110(i.e., the kernel-internal implementation artifact)
4b35dc5d
TR
111only while operations such as
112.BR FUTEX_WAIT ,
113described below, are being performed on a particular futex word.
a663ca5a
MK
114.\"
115.SS Arguments
fea681da
MK
116The
117.I uaddr
077981d4
MK
118argument points to the futex word.
119On all platforms, futexes are four-byte
4b35dc5d 120integers that must be aligned on a four-byte boundary.
f388ba70
MK
121The operation to perform on the futex is specified in the
122.I futex_op
123argument;
124.IR val
125is a value whose meaning and purpose depends on
126.IR futex_op .
36ab2074
MK
127
128The remaining arguments
129.RI ( timeout ,
130.IR uaddr2 ,
131and
132.IR val3 )
133are required only for certain of the futex operations described below.
134Where one of these arguments is not required, it is ignored.
768d3c23 135
36ab2074
MK
136For several blocking operations, the
137.I timeout
138argument is a pointer to a
139.IR timespec
140structure that specifies a timeout for the operation.
141However, notwithstanding the prototype shown above, for some operations,
10022b8e 142the least significant four bytes are used as an integer whose meaning
36ab2074 143is determined by the operation.
768d3c23
MK
144For these operations, the kernel casts the
145.I timeout
10022b8e
HS
146value first to
147.IR "unsigned long",
148then to
c6dc40a2 149.IR uint32_t ,
768d3c23
MK
150and in the remainder of this page, this argument is referred to as
151.I val2
152when interpreted in this fashion.
153
de5a3bb4 154Where it is required, the
36ab2074 155.IR uaddr2
4c8cb0ff
MK
156argument is a pointer to a second futex word that is employed
157by the operation.
36ab2074
MK
158The interpretation of the final integer argument,
159.IR val3 ,
160depends on the operation.
a663ca5a
MK
161.\"
162.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
163.\"
164.SS Futex operations
6be4bad7 165The
d33602c4 166.I futex_op
6be4bad7
MK
167argument consists of two parts:
168a command that specifies the operation to be performed,
169bit-wise ORed with zero or or more options that
170modify the behaviour of the operation.
fc30eb79 171The options that may be included in
d33602c4 172.I futex_op
fc30eb79
TG
173are as follows:
174.TP
175.BR FUTEX_PRIVATE_FLAG " (since Linux 2.6.22)"
176.\" commit 34f01cc1f512fa783302982776895c73714ebbc2
177This option bit can be employed with all futex operations.
e45f9735 178It tells the kernel that the futex is process-private and not shared
0c3ec26b
MK
179with another process (i.e., it is being used for synchronization
180only between threads of the same process).
943ccc52
MK
181This allows the kernel to make some additional performance optimizations.
182.\" I.e., It allows the kernel choose the fast path for validating
183.\" the user-space address and avoids expensive VMA lookups,
184.\" taking reference counts on file backing store, and so on.
ae2c1774
MK
185
186As a convenience,
187.IR <linux/futex.h>
188defines a set of constants with the suffix
189.BR _PRIVATE
190that are equivalents of all of the operations listed below,
dcdfde26 191.\" except the obsolete FUTEX_FD, for which the "private" flag was
ae2c1774
MK
192.\" meaningless
193but with the
194.BR FUTEX_PRIVATE_FLAG
195ORed into the constant value.
196Thus, there are
197.BR FUTEX_WAIT_PRIVATE ,
198.BR FUTEX_WAKE_PRIVATE ,
199and so on.
2e98bbc2
TG
200.TP
201.BR FUTEX_CLOCK_REALTIME " (since Linux 2.6.28)"
202.\" commit 1acdac104668a0834cfa267de9946fac7764d486
4a7e5b05 203This option bit can be employed only with the
2e98bbc2
TG
204.BR FUTEX_WAIT_BITSET
205and
206.BR FUTEX_WAIT_REQUEUE_PI
c84cf68c 207operations.
2e98bbc2 208
f2103b26
MK
209If this option is set, the kernel treats
210.I timeout
211as an absolute time based on
2e98bbc2
TG
212.BR CLOCK_REALTIME .
213
f2103b26
MK
214If this option is not set, the kernel treats
215.I timeout
216as relative time,
d6bb5a38 217.\" FIXME XXX I added CLOCK_MONOTONIC below. Okay?
1c952cf5
MK
218measured against the
219.BR CLOCK_MONOTONIC
220clock.
6be4bad7
MK
221.PP
222The operation specified in
d33602c4 223.I futex_op
6be4bad7 224is one of the following:
70b06b90
MK
225.\"
226.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
227.\"
fea681da 228.TP
81c9d87e
MK
229.BR FUTEX_WAIT " (since Linux 2.6.0)"
230.\" Strictly speaking, since some time in 2.5.x
f065673c 231This operation tests that the value at the
4b35dc5d 232futex word pointed to by the address
fea681da 233.I uaddr
4b35dc5d 234still contains the expected value
fea681da 235.IR val ,
4b35dc5d 236and if so, then sleeps awaiting
682edefb 237.B FUTEX_WAKE
077981d4
MK
238on the futex word.
239The load of the value of the futex word is an atomic memory
4b35dc5d 240access (i.e., using atomic machine instructions of the respective
077981d4
MK
241architecture).
242This load, the comparison with the expected value, and
4b35dc5d 243starting to sleep are performed atomically and totally ordered with respect
077981d4
MK
244to other futex operations on the same futex word.
245If the thread starts to
4b35dc5d 246sleep, it is considered a waiter on this futex word.
f065673c
MK
247If the futex value does not match
248.IR val ,
4710334a 249then the call fails immediately with the error
badbf70c 250.BR EAGAIN .
4b35dc5d
TR
251
252The purpose of the comparison with the expected value is to prevent lost
253wake-ups: If another thread changed the value of the futex word after the
254calling thread decided to block based on the prior value, and if the other
255thread executed a
256.BR FUTEX_WAKE
257operation (or similar wake-up) after the value change and before this
f065673c 258.BR FUTEX_WAIT
4b35dc5d
TR
259operation, then the latter will observe the value change and will not start
260to sleep.
1909e523 261
c13182ef 262If the
fea681da 263.I timeout
53ba4030 264argument is non-NULL, its contents specify a relative timeout for the wait,
d6bb5a38 265.\" FIXME XXX I added CLOCK_MONOTONIC below. Okay?
1c952cf5
MK
266measured according to the
267.BR CLOCK_MONOTONIC
268clock.
82a6092b
MK
269(This interval will be rounded up to the system clock granularity,
270and kernel scheduling delays mean that the
271blocking interval may overrun by a small amount.)
272If
273.I timeout
274is NULL, the call blocks indefinitely.
4798a7f3 275
c13182ef 276The arguments
fea681da
MK
277.I uaddr2
278and
279.I val3
280are ignored.
281
74f58a64
MK
282.\" FIXME(Torvald) I think we should remove this. Or maybe adapt to a
283.\" different example.
4b35dc5d
TR
284.\" For
285.\" .BR futex (7),
286.\" this call is executed if decrementing the count gave a negative value
287.\" (indicating contention),
288.\" and will sleep until another process or thread releases
289.\" the futex and executes the
290.\" .B FUTEX_WAKE
291.\" operation.
70b06b90
MK
292.\"
293.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
294.\"
fea681da 295.TP
81c9d87e
MK
296.BR FUTEX_WAKE " (since Linux 2.6.0)"
297.\" Strictly speaking, since Linux 2.5.x
f065673c
MK
298This operation wakes at most
299.I val
4b35dc5d 300of the waiters that are waiting (e.g., inside
f065673c 301.BR FUTEX_WAIT )
4b35dc5d 302on the futex word at the address
f065673c
MK
303.IR uaddr .
304Most commonly,
305.I val
306is specified as either 1 (wake up a single waiter) or
307.BR INT_MAX
308(wake up all waiters).
730bfbda
MK
309No guarantee is provided about which waiters are awoken
310(e.g., a waiter with a higher scheduling priority is not guaranteed
311to be awoken in preference to a waiter with a lower priority).
4798a7f3 312
fea681da
MK
313The arguments
314.IR timeout ,
c8b921bd 315.IR uaddr2 ,
fea681da
MK
316and
317.I val3
318are ignored.
319
74f58a64
MK
320.\" FIXME(Torvald) I think we should remove this. Or maybe adapt to
321.\" a different example.
4c8cb0ff
MK
322.\" For
323.\" .BR futex (7),
324.\" this is executed if incrementing the count showed that
325.\" there were waiters,
326.\" once the futex value has been set to 1
327.\" (indicating that it is available).
328.\"
329.\" FIXME How does "incrementing the count show that there were waiters"?
70b06b90
MK
330.\"
331.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
332.\"
a7c2bf45
MK
333.TP
334.BR FUTEX_FD " (from Linux 2.6.0 up to and including Linux 2.6.25)"
335.\" Strictly speaking, from Linux 2.5.x to 2.6.25
4c8cb0ff
MK
336This operation creates a file descriptor that is associated with
337the futex at
a7c2bf45 338.IR uaddr .
bdc5957a
MK
339The caller must close the returned file descriptor after use.
340When another process or thread performs a
a7c2bf45 341.BR FUTEX_WAKE
4b35dc5d 342on the futex word, the file descriptor indicates as being readable with
a7c2bf45
MK
343.BR select (2),
344.BR poll (2),
345and
346.BR epoll (7)
347
f1d2171d 348The file descriptor can be used to obtain asynchronous notifications: if
a7c2bf45 349.I val
bdc5957a 350is nonzero, then when another process or thread executes a
a7c2bf45
MK
351.BR FUTEX_WAKE ,
352the caller will receive the signal number that was passed in
353.IR val .
354
355The arguments
356.IR timeout ,
357.I uaddr2
358and
359.I val3
360are ignored.
361
4c8cb0ff
MK
362.\" FIXME(Torvald) We never define "upped". Maybe just remove the
363.\" following sentence?
a7c2bf45
MK
364To prevent race conditions, the caller should test if the futex has
365been upped after
366.B FUTEX_FD
367returns.
368
369Because it was inherently racy,
370.B FUTEX_FD
371has been removed
372.\" commit 82af7aca56c67061420d618cc5a30f0fd4106b80
373from Linux 2.6.26 onward.
70b06b90
MK
374.\"
375.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
376.\"
a7c2bf45
MK
377.TP
378.BR FUTEX_REQUEUE " (since Linux 2.6.0)"
379.\" Strictly speaking: from Linux 2.5.70
d6bb5a38
MK
380.\" FIXME(Torvald) Is there some indication that FUTEX_REQUEUE is broken
381.\" in general, or is this comment implicitly speaking about the
382.\" condvar (?) use case? If the latter we might want to weaken the
383.\" advice below a little.
384.\" [Anyone else have input on this?]
385.\"
a7c2bf45 386.IR "Avoid using this operation" .
4b35dc5d 387It is broken for its intended purpose.
a7c2bf45
MK
388Use
389.BR FUTEX_CMP_REQUEUE
390instead.
391
392This operation performs the same task as
393.BR FUTEX_CMP_REQUEUE ,
394except that no check is made using the value in
395.IR val3 .
396(The argument
397.I val3
398is ignored.)
70b06b90
MK
399.\"
400.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
401.\"
a7c2bf45
MK
402.TP
403.BR FUTEX_CMP_REQUEUE " (since Linux 2.6.7)"
4b35dc5d 404This operation first checks whether the location
a7c2bf45
MK
405.I uaddr
406still contains the value
407.IR val3 .
408If not, the operation fails with the error
409.BR EAGAIN .
4b35dc5d 410Otherwise, the operation wakes up a maximum of
a7c2bf45
MK
411.I val
412waiters that are waiting on the futex at
413.IR uaddr .
414If there are more than
415.I val
416waiters, then the remaining waiters are removed
417from the wait queue of the source futex at
418.I uaddr
419and added to the wait queue of the target futex at
420.IR uaddr2 .
421The
768d3c23 422.I val2
936876a9 423argument specifies an upper limit on the number of waiters
a7c2bf45 424that are requeued to the futex at
768d3c23 425.IR uaddr2 .
a7c2bf45 426
d6bb5a38
MK
427.\" FIXME(Torvald) Is the following correct? Or is just the decision
428.\" which threads to wake or requeue part of the atomic operation?
4b35dc5d
TR
429The load from
430.I uaddr
4c8cb0ff
MK
431is an atomic memory access (i.e., using atomic machine instructions of
432the respective architecture).
077981d4 433This load, the comparison with
4b35dc5d 434.IR val3 ,
4c8cb0ff
MK
435and the requeueing of any waiters are performed atomically and totally
436ordered with respect to other operations on the same futex word.
4b35dc5d
TR
437
438This operation was added as a replacement for the earlier
439.BR FUTEX_REQUEUE .
440The difference is that the check of the value at
441.I uaddr
0c3ec26b 442can be used to ensure that requeueing happens only under certain
4c8cb0ff 443conditions.
4b35dc5d
TR
444Both operations can be used to avoid a "thundering herd" effect when
445.B FUTEX_WAKE
4c8cb0ff
MK
446is used and all of the waiters that are woken need to acquire
447another futex.
4b35dc5d 448
a7c2bf45
MK
449.\" FIXME Please review the following new paragraph to see if it is
450.\" accurate.
451Typical values to specify for
452.I val
453are 0 or or 1.
454(Specifying
455.BR INT_MAX
456is not useful, because it would make the
457.BR FUTEX_CMP_REQUEUE
458operation equivalent to
459.BR FUTEX_WAKE .)
936876a9 460The limit value specified via
768d3c23
MK
461.I val2
462is typically either 1 or
a7c2bf45
MK
463.BR INT_MAX .
464(Specifying the argument as 0 is not useful, because it would make the
465.BR FUTEX_CMP_REQUEUE
466operation equivalent to
467.BR FUTEX_WAIT .)
6bac3b85 468.\"
43d16602
MK
469.\" FIXME Here, it would be helpful to have an example of how
470.\" FUTEX_CMP_REQUEUE might be used, at the same time illustrating
471.\" why FUTEX_WAKE is unsuitable for the same use case.
472.\"
70b06b90
MK
473.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
474.\"
a5956430
MK
475.\" FIXME I added a lengthy piece of text on FUTEX_WAKE_OP text,
476.\" and I'd be happy if someone checked it.
fea681da 477.TP
d67e21f5
MK
478.BR FUTEX_WAKE_OP " (since Linux 2.6.14)"
479.\" commit 4732efbeb997189d9f9b04708dc26bf8613ed721
6bac3b85
MK
480.\" Author: Jakub Jelinek <jakub@redhat.com>
481.\" Date: Tue Sep 6 15:16:25 2005 -0700
4c8cb0ff
MK
482.\" FIXME(Torvald) The glibc condvar implementation is currently being
483.\" revised (e.g., to not use an internal lock anymore).
484.\" It is probably more future-proof to remove this paragraph.
d6bb5a38 485.\" [Torvald, do you have an update here?]
6bac3b85
MK
486This operation was added to support some user-space use cases
487where more than one futex must be handled at the same time.
488The most notable example is the implementation of
489.BR pthread_cond_signal (3),
490which requires operations on two futexes,
491the one used to implement the mutex and the one used in the implementation
492of the wait queue associated with the condition variable.
493.BR FUTEX_WAKE_OP
494allows such cases to be implemented without leading to
495high rates of contention and context switching.
496
497The
498.BR FUTEX_WAIT_OP
e61abc20 499operation is equivalent to executing the following code atomically
4c8cb0ff
MK
500and totally ordered with respect to other futex operations on
501any of the two supplied futex words:
6bac3b85
MK
502
503.in +4n
504.nf
505int oldval = *(int *) uaddr2;
506*(int *) uaddr2 = oldval \fIop\fP \fIoparg\fP;
507futex(uaddr, FUTEX_WAKE, val, 0, 0, 0);
508if (oldval \fIcmp\fP \fIcmparg\fP)
768d3c23 509 futex(uaddr2, FUTEX_WAKE, val2, 0, 0, 0);
6bac3b85
MK
510.fi
511.in
512
513In other words,
514.BR FUTEX_WAIT_OP
515does the following:
516.RS
517.IP * 3
4b35dc5d
TR
518saves the original value of the futex word at
519.IR uaddr2
520and performs an operation to modify the value of the futex at
6bac3b85 521.IR uaddr2 ;
4c8cb0ff
MK
522this is an atomic read-modify-write memory access (i.e., using atomic
523machine instructions of the respective architecture)
6bac3b85
MK
524.IP *
525wakes up a maximum of
526.I val
4b35dc5d 527waiters on the futex for the futex word at
6bac3b85
MK
528.IR uaddr ;
529and
530.IP *
4c8cb0ff
MK
531dependent on the results of a test of the original value of the
532futex word at
6bac3b85
MK
533.IR uaddr2 ,
534wakes up a maximum of
768d3c23 535.I val2
4b35dc5d 536waiters on the futex for the futex word at
6bac3b85
MK
537.IR uaddr2 .
538.RE
539.IP
6bac3b85
MK
540The operation and comparison that are to be performed are encoded
541in the bits of the argument
542.IR val3 .
543Pictorially, the encoding is:
544
f6af90e7 545.in +8n
6bac3b85 546.nf
f6af90e7
MK
547+---+---+-----------+-----------+
548|op |cmp| oparg | cmparg |
549+---+---+-----------+-----------+
550 4 4 12 12 <== # of bits
6bac3b85
MK
551.fi
552.in
553
554Expressed in code, the encoding is:
555
556.in +4n
557.nf
558#define FUTEX_OP(op, oparg, cmp, cmparg) \\
559 (((op & 0xf) << 28) | \\
560 ((cmp & 0xf) << 24) | \\
561 ((oparg & 0xfff) << 12) | \\
562 (cmparg & 0xfff))
563.fi
564.in
565
566In the above,
567.I op
568and
569.I cmp
570are each one of the codes listed below.
571The
572.I oparg
573and
574.I cmparg
575components are literal numeric values, except as noted below.
576
577The
578.I op
579component has one of the following values:
580
581.in +4n
582.nf
583FUTEX_OP_SET 0 /* uaddr2 = oparg; */
584FUTEX_OP_ADD 1 /* uaddr2 += oparg; */
585FUTEX_OP_OR 2 /* uaddr2 |= oparg; */
586FUTEX_OP_ANDN 3 /* uaddr2 &= ~oparg; */
587FUTEX_OP_XOR 4 /* uaddr2 ^= oparg; */
588.fi
589.in
590
591In addition, bit-wise ORing the following value into
592.I op
593causes
594.IR "(1\ <<\ oparg)"
595to be used as the operand:
596
597.in +4n
598.nf
599FUTEX_OP_ARG_SHIFT 8 /* Use (1 << oparg) as operand */
600.fi
601.in
602
603The
604.I cmp
605field is one of the following:
606
607.in +4n
608.nf
609FUTEX_OP_CMP_EQ 0 /* if (oldval == cmparg) wake */
610FUTEX_OP_CMP_NE 1 /* if (oldval != cmparg) wake */
611FUTEX_OP_CMP_LT 2 /* if (oldval < cmparg) wake */
612FUTEX_OP_CMP_LE 3 /* if (oldval <= cmparg) wake */
613FUTEX_OP_CMP_GT 4 /* if (oldval > cmparg) wake */
614FUTEX_OP_CMP_GE 5 /* if (oldval >= cmparg) wake */
615.fi
616.in
617
618The return value of
619.BR FUTEX_WAKE_OP
620is the sum of the number of waiters woken on the futex
621.IR uaddr
622plus the number of waiters woken on the futex
623.IR uaddr2 .
70b06b90
MK
624.\"
625.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
626.\"
d67e21f5 627.TP
79c9b436
TG
628.BR FUTEX_WAIT_BITSET " (since Linux 2.6.25)"
629.\" commit cd689985cf49f6ff5c8eddc48d98b9d581d9475d
fd9e59d4 630This operation is like
79c9b436
TG
631.BR FUTEX_WAIT
632except that
633.I val3
634is used to provide a 32-bit bitset to the kernel.
635This bitset is stored in the kernel-internal state of the waiter.
636See the description of
637.BR FUTEX_WAKE_BITSET
638for further details.
639
fd9e59d4
MK
640The
641.BR FUTEX_WAIT_BITSET
9732dd8b 642operation also interprets the
fd9e59d4
MK
643.I timeout
644argument differently from
645.BR FUTEX_WAIT .
646See the discussion of
647.BR FUTEX_CLOCK_REALTIME ,
648above.
649
79c9b436
TG
650The
651.I uaddr2
652argument is ignored.
70b06b90
MK
653.\"
654.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
655.\"
79c9b436 656.TP
d67e21f5
MK
657.BR FUTEX_WAKE_BITSET " (since Linux 2.6.25)"
658.\" commit cd689985cf49f6ff5c8eddc48d98b9d581d9475d
55cc422d
TG
659This operation is the same as
660.BR FUTEX_WAKE
661except that the
662.I val3
663argument is used to provide a 32-bit bitset to the kernel.
98d769c0
MK
664This bitset is used to select which waiters should be woken up.
665The selection is done by a bit-wise AND of the "wake" bitset
666(i.e., the value in
667.IR val3 )
668and the bitset which is stored in the kernel-internal
09cb4ce7 669state of the waiter (the "wait" bitset that is set using
98d769c0
MK
670.BR FUTEX_WAIT_BITSET ).
671All of the waiters for which the result of the AND is nonzero are woken up;
672the remaining waiters are left sleeping.
673
d6bb5a38 674.\" FIXME XXX Is this next paragraph that I added okay?
e9d4496b
MK
675The effect of
676.BR FUTEX_WAIT_BITSET
677and
678.BR FUTEX_WAKE_BITSET
9732dd8b
MK
679is to allow selective wake-ups among multiple waiters that are blocked
680on the same futex.
09cb4ce7 681Note, however, that using this bitset multiplexing feature on a
e9d4496b
MK
682futex is less efficient than simply using multiple futexes,
683because employing bitset multiplexing requires the kernel
684to check all waiters on a futex,
685including those that are not interested in being woken up
686(i.e., they do not have the relevant bit set in their "wait" bitset).
687.\" According to http://locklessinc.com/articles/futex_cheat_sheet/:
688.\"
689.\" "The original reason for the addition of these extensions
690.\" was to improve the performance of pthread read-write locks
691.\" in glibc. However, the pthreads library no longer uses the
692.\" same locking algorithm, and these extensions are not used
693.\" without the bitset parameter being all ones.
694.\"
695.\" The page goes on to note that the FUTEX_WAIT_BITSET operation
696.\" is nevertheless used (with a bitset of all ones) in order to
697.\" obtain the absolute timeout functionality that is useful
698.\" for efficiently implementing Pthreads APIs (which use absolute
699.\" timeouts); FUTEX_WAIT provides only relative timeouts.
700
98d769c0
MK
701The
702.I uaddr2
703and
704.I timeout
705arguments are ignored.
9732dd8b
MK
706
707The
708.BR FUTEX_WAIT
709and
710.BR FUTEX_WAKE
711operations correspond to
712.BR FUTEX_WAIT_BITSET
713and
714.BR FUTEX_WAKE_BITSET
715operations where the bitsets are all ones.
bd90a5f9 716.\"
70b06b90 717.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
bd90a5f9
MK
718.\"
719.SS Priority-inheritance futexes
b52e1cd4
MK
720Linux supports priority-inheritance (PI) futexes in order to handle
721priority-inversion problems that can be encountered with
722normal futex locks.
b565548b 723Priority inversion is the problem that occurs when a high-priority
bdc5957a
MK
724task is blocked waiting to acquire a lock held by a low-priority task,
725while tasks at an intermediate priority continuously preempt
726the low-priority task from the CPU.
727Consequently, the low-priority task makes no progress toward
728releasing the lock, and the high-priority task remains blocked.
7f315ae3 729
7d20efd7
MK
730Priority inheritance is a mechanism for dealing with
731the priority-inversion problem.
bdc5957a
MK
732With this mechanism, when a high-priority task becomes blocked
733by a lock held by a low-priority task,
7d20efd7 734the latter's priority is temporarily raised to that of the former,
bdc5957a 735so that it is not preempted by any intermediate level tasks,
7d20efd7
MK
736and can thus make progress toward releasing the lock.
737To be effective, priority inheritance must be transitive,
bdc5957a
MK
738meaning that if a high-priority task blocks on a lock
739held by a lower-priority task that is itself blocked by lock
740held by another intermediate-priority task
7d20efd7 741(and so on, for chains of arbitrary length),
bdc5957a
MK
742then both of those task
743(or more generally, all of the tasks in a lock chain)
744have their priorities raised to be the same as the high-priority task.
7d20efd7 745
9e2b90ee
MK
746.\" FIXME XXX The following is my attempt at a definition of PI futexes,
747.\" based on mail discussions with Darren Hart. Does it seem okay?
748From a user-space perspective,
749what makes a futex PI-aware is a policy agreement between user space
4b35dc5d 750and the kernel about the value of the futex word (described in a moment),
9e2b90ee
MK
751coupled with the use of the PI futex operations described below
752(in particular,
753.BR FUTEX_LOCK_PI ,
754.BR FUTEX_TRYLOCK_PI ,
755and
756.BR FUTEX_CMP_REQUEUE_PI ).
757.\" Quoting Darren Hart:
758.\" These opcodes paired with the PI futex value policy (described below)
759.\" defines a "futex" as PI aware. These were created very specifically
760.\" in support of PI pthread_mutexes, so it makes a lot more sense to
761.\" talk about a PI aware pthread_mutex, than a PI aware futex, since
762.\" there is a lot of policy and scaffolding that has to be built up
763.\" around it to use it properly (this is what a PI pthread_mutex is).
764
f1d2171d 765.\" FIXME XXX ===== Start of adapted Hart/Guniguntala text =====
1af427a4
MK
766.\" The following text is drawn from the Hart/Guniguntala paper
767.\" (listed in SEE ALSO), but I have reworded some pieces
768.\" significantly. Please check it.
79d918c7
MK
769.\"
770The PI futex operations described below differ from the other
4b35dc5d
TR
771futex operations in that they impose policy on the use of the value of the
772futex word:
79d918c7 773.IP * 3
4b35dc5d 774If the lock is not acquired, the futex word's value shall be 0.
79d918c7 775.IP *
4c8cb0ff
MK
776If the lock is acquired, the futex word's value shall
777be the thread ID (TID;
4b35dc5d 778see
79d918c7
MK
779.BR gettid (2))
780of the owning thread.
781.IP *
f1d2171d 782.\" FIXME XXX In the following line, I added "the lock is owned and". Okay?
79d918c7
MK
783If the lock is owned and there are threads contending for the lock,
784then the
785.B FUTEX_WAITERS
4b35dc5d 786bit shall be set in the futex word's value; in other words, this value is:
79d918c7
MK
787
788 FUTEX_WAITERS | TID
9e2b90ee 789
79d918c7 790.PP
4b35dc5d 791Note that a PI futex word never just has the value
9e2b90ee
MK
792.BR FUTEX_WAITERS ,
793which is a permissible state for non-PI futexes.
794
79d918c7 795With this policy in place,
4b35dc5d
TR
796a user-space application can acquire a not-acquired
797lock or release a lock that no other threads try to acquire using atomic
4c8cb0ff
MK
798instructions executed in user space (e.g., a compare-and-swap operation
799such as
b52e1cd4
MK
800.I cmpxchg
801on the x86 architecture).
4c8cb0ff
MK
802Acquiring a lock simply consists of using compare-and-swap to atomically
803set the futex word's value to the caller's TID if its previous value was 0.
4b35dc5d
TR
804Releasing a lock requires using compare-and-swap to set the futex word's
805value to 0 if the previous value was the expected TID.
b52e1cd4 806
4b35dc5d 807If a futex is already acquired (i.e., has a nonzero value),
b52e1cd4 808waiters must employ the
79d918c7
MK
809.B FUTEX_LOCK_PI
810operation to acquire the lock.
4b35dc5d 811If other threads are waiting for the lock, then the
79d918c7 812.B FUTEX_WAITERS
4c8cb0ff
MK
813bit is set in the futex value;
814in this case, the lock owner must employ the
79d918c7 815.B FUTEX_UNLOCK_PI
b52e1cd4
MK
816operation to release the lock.
817
79d918c7
MK
818In the cases where callers are forced into the kernel
819(i.e., required to perform a
820.BR futex ()
0c3ec26b 821call),
79d918c7
MK
822they then deal directly with a so-called RT-mutex,
823a kernel locking mechanism which implements the required
824priority-inheritance semantics.
825After the RT-mutex is acquired, the futex value is updated accordingly,
826before the calling thread returns to user space.
827.\" FIXME ===== End of adapted Hart/Guniguntala text =====
828
a59fca75 829It is important to note
d6bb5a38
MK
830.\" FIXME We need some explanation in the following paragraph of *why*
831.\" it is important to note that "the kernel will update the
832.\" futex word's value prior
833to returning to user space" . Can someone explain?
4b35dc5d 834that the kernel will update the futex word's value prior
79d918c7
MK
835to returning to user space.
836Unlike the other futex operations described above,
837the PI futex operations are designed
d9d5be6b 838for the implementation of very specific IPC mechanisms.
fc57e6bb 839.\"
7bd3ffbc 840.\" FIXME XXX In discussing errors for FUTEX_CMP_REQUEUE_PI, Darren Hart
99c0ac69
MK
841.\" made the observation that "EINVAL is returned if the non-pi
842.\" to pi or op pairing semantics are violated."
843.\" Probably there needs to be a general statement about this
844.\" requirement, probably located at about this point in the page.
d6bb5a38 845.\" Darren (or someone else), care to take a shot at this?
dd003bef
MK
846.\"
847.\" FIXME Somewhere on this page (I guess under the discussion of PI
848.\" futexes) we need a discussion of the FUTEX_OWNER_DIED bit.
849.\" Can someone propose a text?
bd90a5f9
MK
850
851PI futexes are operated on by specifying one of the following values in
852.IR futex_op :
70b06b90
MK
853.\"
854.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
855.\"
d67e21f5
MK
856.TP
857.BR FUTEX_LOCK_PI " (since Linux 2.6.18)"
858.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
67833bec 859.\"
d6bb5a38
MK
860.\" FIXME I did some significant rewording of tglx's text to create
861.\" the text below.
862.\" Please check the following paragraph, in case I injected
863.\" errors.
67833bec
MK
864.\"
865This operation is used after after an attempt to acquire
4b35dc5d
TR
866the lock via an atomic user-space instruction failed
867because the futex word has a nonzero value\(emspecifically,
67833bec 868because it contained the namespace-specific TID of the lock owner.
67259526 869.\" FIXME In the preceding line, what does "namespace-specific" mean?
67833bec 870.\" (I kept those words from tglx.)
67259526 871.\" That is, what kind of namespace are we talking about?
67833bec
MK
872.\" (I suppose we are talking PID namespaces here, but I want to
873.\" be sure.)
874
4b35dc5d 875The operation checks the value of the futex word at the address
67833bec 876.IR uaddr .
70b06b90
MK
877If the value is 0, then the kernel tries to atomically set
878the futex value to the caller's TID.
d6bb5a38
MK
879.\" FIXME What would be the cause(s) of failure referred to
880.\" in the following sentence?
67833bec 881If that fails,
4b35dc5d 882or the futex word's value is nonzero,
67833bec 883the kernel atomically sets the
e0547e70 884.B FUTEX_WAITERS
67833bec
MK
885bit, which signals the futex owner that it cannot unlock the futex in
886user space atomically by setting the futex value to 0.
887After that, the kernel tries to find the thread which is
888associated with the owner TID,
889.\" FIXME Could I get a bit more detail on the next two lines?
890.\" What is "creates or reuses kernel state" about?
d6bb5a38 891.\" (I think this needs to be clearer in the page)
67833bec
MK
892creates or reuses kernel state on behalf of the owner
893and attaches the waiter to it.
67259526
MK
894.\" FIXME In the next line, what type of "priority" are we talking about?
895.\" Realtime priorities for SCHED_FIFO and SCHED_RR?
896.\" Or something else?
1f043693 897The enqueueing of the waiter is in descending priority order if more
e0547e70 898than one waiter exists.
67259526 899.\" FIXME What does "bandwidth" refer to in the next line?
e0547e70 900The owner inherits either the priority or the bandwidth of the waiter.
67259526
MK
901.\" FIXME In the preceding line, what determines whether the
902.\" owner inherits the priority versus the bandwidth?
67833bec
MK
903.\"
904.\" FIXME Could I get some help translating the next sentence into
905.\" something that user-space developers (and I) can understand?
70b06b90 906.\" In particular, what are "nested locks" in this context?
e0547e70
TG
907This inheritance follows the lock chain in the case of
908nested locking and performs deadlock detection.
909
d6bb5a38 910.\" FIXME tglx said "The timeout argument is handled as described in
9ce19cf1 911.\" FUTEX_WAIT." However, it appears to me that this is not right.
70b06b90 912.\" Is the following formulation correct?
e0547e70
TG
913The
914.I timeout
9ce19cf1
MK
915argument provides a timeout for the lock attempt.
916It is interpreted as an absolute time, measured against the
917.BR CLOCK_REALTIME
918clock.
919If
920.I timeout
921is NULL, the operation will block indefinitely.
e0547e70 922
a449c634 923The
e0547e70
TG
924.IR uaddr2 ,
925.IR val ,
926and
927.IR val3
a449c634 928arguments are ignored.
67833bec 929.\"
70b06b90
MK
930.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
931.\"
d67e21f5 932.TP
12fdbe23 933.BR FUTEX_TRYLOCK_PI " (since Linux 2.6.18)"
d67e21f5 934.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
12fdbe23
MK
935This operation tries to acquire the futex at
936.IR uaddr .
0b761826 937.\" FIXME I think it would be helpful here to say a few more words about
70b06b90
MK
938.\" the difference(s) between FUTEX_LOCK_PI and FUTEX_TRYLOCK_PI.
939.\" Can someone propose something?
940.\"
74f58a64
MK
941.\" FIXME(Torvald) Additionally, we claim above that just FUTEX_WAITERS
942.\" is never an allowed state.
fa0388c3 943It deals with the situation where the TID value at
12fdbe23
MK
944.I uaddr
945is 0, but the
b52e1cd4 946.B FUTEX_WAITERS
12fdbe23 947bit is set.
fa0388c3
MK
948.\" FIXME How does the situation in the previous sentence come about?
949.\" Probably it would be helpful to say something about that in
950.\" the man page.
badbf70c 951.\" FIXME And *how* does FUTEX_TRYLOCK_PI deal with this situation?
a282e5b0 952User space cannot handle this condition in a race-free manner
084744ef
MK
953
954The
955.IR uaddr2 ,
956.IR val ,
957.IR timeout ,
958and
959.IR val3
960arguments are ignored.
70b06b90
MK
961.\"
962.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
963.\"
d67e21f5 964.TP
12fdbe23 965.BR FUTEX_UNLOCK_PI " (since Linux 2.6.18)"
d67e21f5 966.\" commit c87e2837be82df479a6bae9f155c43516d2feebc
d4ba4328 967This operation wakes the top priority waiter that is waiting in
ecae2099
TG
968.B FUTEX_LOCK_PI
969on the futex address provided by the
970.I uaddr
971argument.
972
973This is called when the user space value at
974.I uaddr
975cannot be changed atomically from a TID (of the owner) to 0.
976
977The
978.IR uaddr2 ,
979.IR val ,
980.IR timeout ,
981and
982.IR val3
11a194bf 983arguments are ignored.
70b06b90
MK
984.\"
985.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
986.\"
d67e21f5 987.TP
d67e21f5
MK
988.BR FUTEX_CMP_REQUEUE_PI " (since Linux 2.6.31)"
989.\" commit 52400ba946759af28442dee6265c5c0180ac7122
f812a08b
DH
990This operation is a PI-aware variant of
991.BR FUTEX_CMP_REQUEUE .
992It requeues waiters that are blocked via
993.B FUTEX_WAIT_REQUEUE_PI
994on
995.I uaddr
996from a non-PI source futex
997.RI ( uaddr )
998to a PI target futex
999.RI ( uaddr2 ).
1000
9e54d26d
MK
1001As with
1002.BR FUTEX_CMP_REQUEUE ,
1003this operation wakes up a maximum of
1004.I val
1005waiters that are waiting on the futex at
1006.IR uaddr .
1007However, for
1008.BR FUTEX_CMP_REQUEUE_PI ,
1009.I val
6fbeb8f4 1010is required to be 1
939ca89f 1011(since the main point is to avoid a thundering herd).
9e54d26d
MK
1012The remaining waiters are removed from the wait queue of the source futex at
1013.I uaddr
1014and added to the wait queue of the target futex at
1015.IR uaddr2 .
f812a08b 1016
9e54d26d 1017The
768d3c23 1018.I val2
c6d8cf21
MK
1019.\" val2 is the cap on the number of requeued waiters.
1020.\" In the glibc pthread_cond_broadcast() implementation, this argument
1021.\" is specified as INT_MAX, and for pthread_cond_signal() it is 0.
9e54d26d 1022and
768d3c23 1023.I val3
9e54d26d
MK
1024arguments serve the same purposes as for
1025.BR FUTEX_CMP_REQUEUE .
70b06b90 1026.\"
be376673
MK
1027.\" FIXME The page at http://locklessinc.com/articles/futex_cheat_sheet/
1028.\" notes that "priority-inheritance Futex to priority-inheritance
1029.\" Futex requeues are currently unsupported". Do we need to say
1030.\" something in the man page about that?
70b06b90
MK
1031.\"
1032.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1033.\"
d67e21f5
MK
1034.TP
1035.BR FUTEX_WAIT_REQUEUE_PI " (since Linux 2.6.31)"
1036.\" commit 52400ba946759af28442dee6265c5c0180ac7122
70b06b90
MK
1037.\"
1038.\" FIXME I find the next sentence (from tglx) pretty hard to grok.
1af427a4 1039.\" Could someone explain it a bit more?
6ff1b4c0
TG
1040Wait operation to wait on a non-PI futex at
1041.I uaddr
1042and potentially be requeued onto a PI futex at
1043.IR uaddr2 .
1044The wait operation on
1045.I uaddr
1046is the same as
1047.BR FUTEX_WAIT .
70b06b90 1048.\"
f1d2171d
MK
1049.\" FIXME I'm not quite clear on the meaning of the following sentence.
1050.\" Is this trying to say that while blocked in a
1051.\" FUTEX_WAIT_REQUEUE_PI, it could happen that another
1052.\" task does a FUTEX_WAKE on uaddr that simply causes
1053.\" a normal wake, with the result that the FUTEX_WAIT_REQUEUE_PI
1054.\" does not complete? What happens then to the FUTEX_WAIT_REQUEUE_PI
1055.\" opertion? Does it remain blocked, or does it unblock
1056.\" In which case, what does user space see?
6ff1b4c0
TG
1057The waiter can be removed from the wait on
1058.I uaddr
1059via
1060.BR FUTEX_WAKE
1061without requeueing on
1062.IR uaddr2 .
a4e69912 1063
63bea7dc
MK
1064.\" FIXME Please check the following. tglx said "The timeout argument
1065.\" is handled as described in FUTEX_WAIT.", but the truth is
1066.\" as below, AFAICS
1067If
1068.I timeout
1069is not NULL, it specifies a timeout for the wait operation;
1070this timeout is interpreted as outlined above in the description of the
1071.BR FUTEX_CLOCK_REALTIME
1072option.
1073If
1074.I timeout
1075is NULL, the operation can block indefinitely.
1076
a4e69912
MK
1077The
1078.I val3
1079argument is ignored.
70b06b90 1080.\" FIXME Re the preceding sentence... Actually 'val3' is internally set to
a4e69912
MK
1081.\" FUTEX_BITSET_MATCH_ANY before calling futex_wait_requeue_pi().
1082.\" I'm not sure we need to say anything about this though.
1083.\" Comments?
abb571e8
MK
1084
1085The
1086.BR FUTEX_WAIT_REQUEUE_PI
1087and
1088.BR FUTEX_CMP_REQUEUE_PI
1089were added to support a fairly specific use case:
1090support for priority-inheritance-aware POSIX threads condition variables.
1091The idea is that these operations should always be paired,
1092in order to ensure that user space and the kernel remain in sync.
1093Thus, in the
1094.BR FUTEX_WAIT_REQUEUE_PI
1095operation, the user-space application pre-specifies the target
1096of the requeue that takes place in the
1097.BR FUTEX_CMP_REQUEUE_PI
1098operation.
1099.\"
1100.\" Darren Hart notes that a patch to allow glibc to fully support
1af427a4 1101.\" PI-aware pthreads condition variables has not yet been accepted into
abb571e8
MK
1102.\" glibc. The story is complex, and can be found at
1103.\" https://sourceware.org/bugzilla/show_bug.cgi?id=11588
1104.\" Darren notes that in the meantime, the patch is shipped with various
1af427a4 1105.\" PREEMPT_RT-enabled Linux systems.
abb571e8
MK
1106.\"
1107.\" Related to the preceding, Darren proposed that somewhere, man-pages
1108.\" should document the following point:
1af427a4 1109.\"
4c8cb0ff
MK
1110.\" While the Linux kernel, since 2.6.31, supports requeueing of
1111.\" priority-inheritance (PI) aware mutexes via the
1112.\" FUTEX_WAIT_REQUEUE_PI and FUTEX_CMP_REQUEUE_PI futex operations,
1113.\" the glibc implementation does not yet take full advantage of this.
1114.\" Specifically, the condvar internal data lock remains a non-PI aware
1115.\" mutex, regardless of the type of the pthread_mutex associated with
1116.\" the condvar. This can lead to an unbounded priority inversion on
1117.\" the internal data lock even when associating a PI aware
1118.\" pthread_mutex with a condvar during a pthread_cond*_wait
1119.\" operation. For this reason, it is not recommended to rely on
1120.\" priority inheritance when using pthread condition variables.
1af427a4
MK
1121.\"
1122.\" The problem is that the obvious location for this text is
1123.\" the pthread_cond*wait(3) man page. However, such a man page
abb571e8 1124.\" does not currently exist.
70b06b90 1125.\"
6700de24 1126.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
70b06b90 1127.\"
47297adb 1128.SH RETURN VALUE
fea681da 1129.PP
a5c5a06a
MK
1130In the event of an error (and assuming that
1131.BR futex ()
1132was invoked via
1133.BR syscall (2)),
1134all operations return \-1 and set
e808bba0 1135.I errno
6f147f79 1136to indicate the cause of the error.
e808bba0
MK
1137The return value on success depends on the operation,
1138as described in the following list:
fea681da
MK
1139.TP
1140.B FUTEX_WAIT
077981d4 1141Returns 0 if the caller was woken up.
4c8cb0ff
MK
1142Note that a wake-up can also be caused by common futex usage patterns
1143in unrelated code that happened to have previously used the futex word's
1144memory location (e.g., typical futex-based implementations of
1145Pthreads mutexes can cause this under some conditions).
1146Therefore, callers should always conservatively assume that a return
1147value of 0 can mean a spurious wake-up, and use the futex word's value
1148(i.e., the user space synchronization scheme)
1149 to decide whether to continue to block or not.
fea681da
MK
1150.TP
1151.B FUTEX_WAKE
bdc5957a 1152Returns the number of waiters that were woken up.
fea681da
MK
1153.TP
1154.B FUTEX_FD
1155Returns the new file descriptor associated with the futex.
1156.TP
1157.B FUTEX_REQUEUE
bdc5957a 1158Returns the number of waiters that were woken up.
fea681da
MK
1159.TP
1160.B FUTEX_CMP_REQUEUE
bdc5957a 1161Returns the total number of waiters that were woken up or
4b35dc5d 1162requeued to the futex for the futex word at
3dfcc11d
MK
1163.IR uaddr2 .
1164If this value is greater than
1165.IR val ,
4c8cb0ff
MK
1166then difference is the number of waiters requeued to the futex for the
1167futex word at
3dfcc11d 1168.IR uaddr2 .
dcad19c0
MK
1169.TP
1170.B FUTEX_WAKE_OP
a8b5b324 1171Returns the total number of waiters that were woken up.
4c8cb0ff
MK
1172This is the sum of the woken waiters on the two futexes for
1173the futex words at
a8b5b324
MK
1174.I uaddr
1175and
1176.IR uaddr2 .
dcad19c0
MK
1177.TP
1178.B FUTEX_WAIT_BITSET
077981d4
MK
1179Returns 0 if the caller was woken up.
1180See
4b35dc5d
TR
1181.B FUTEX_WAIT
1182for how to interpret this correctly in practice.
dcad19c0
MK
1183.TP
1184.B FUTEX_WAKE_BITSET
bdc5957a 1185Returns the number of waiters that were woken up.
dcad19c0
MK
1186.TP
1187.B FUTEX_LOCK_PI
bf02a260 1188Returns 0 if the futex was successfully locked.
dcad19c0
MK
1189.TP
1190.B FUTEX_TRYLOCK_PI
5c716eef 1191Returns 0 if the futex was successfully locked.
dcad19c0
MK
1192.TP
1193.B FUTEX_UNLOCK_PI
52bb928f 1194Returns 0 if the futex was successfully unlocked.
dcad19c0
MK
1195.TP
1196.B FUTEX_CMP_REQUEUE_PI
bdc5957a 1197Returns the total number of waiters that were woken up or
4b35dc5d 1198requeued to the futex for the futex word at
dddd395a
MK
1199.IR uaddr2 .
1200If this value is greater than
1201.IR val ,
4c8cb0ff
MK
1202then difference is the number of waiters requeued to the futex for
1203the futex word at
dddd395a 1204.IR uaddr2 .
dcad19c0
MK
1205.TP
1206.B FUTEX_WAIT_REQUEUE_PI
4c8cb0ff
MK
1207Returns 0 if the caller was successfully requeued to the futex for
1208the futex word at
22c15de9 1209.IR uaddr2 .
70b06b90
MK
1210.\"
1211.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1212.\"
fea681da
MK
1213.SH ERRORS
1214.TP
1215.B EACCES
4b35dc5d 1216No read access to the memory of a futex word.
fea681da
MK
1217.TP
1218.B EAGAIN
f48516d1 1219.RB ( FUTEX_WAIT ,
4b35dc5d 1220.BR FUTEX_WAIT_BITSET ,
f48516d1 1221.BR FUTEX_WAIT_REQUEUE_PI )
badbf70c
MK
1222The value pointed to by
1223.I uaddr
1224was not equal to the expected value
1225.I val
1226at the time of the call.
9732dd8b
MK
1227
1228.BR Note :
1229on Linux, the symbolic names
1230.B EAGAIN
1231and
1232.B EWOULDBLOCK
77da5feb 1233(both of which appear in different parts of the kernel futex code)
9732dd8b 1234have the same value.
badbf70c
MK
1235.TP
1236.B EAGAIN
8f2068bb
MK
1237.RB ( FUTEX_CMP_REQUEUE ,
1238.BR FUTEX_CMP_REQUEUE_PI )
ce5602fd 1239The value pointed to by
9f6c40c0
МК
1240.I uaddr
1241is not equal to the expected value
1242.IR val3 .
fd1dc4c2 1243.\" FIXME: Is the following sentence correct?
d6bb5a38 1244.\" [I would prefer to remove this sentence. --triegel@redhat.com]
fea681da 1245(This probably indicates a race;
682edefb
MK
1246use the safe
1247.B FUTEX_WAKE
1248now.)
c0091dd3 1249.\"
f1d2171d 1250.\" FIXME XXX Should there be an EAGAIN case for FUTEX_TRYLOCK_PI?
c0091dd3
MK
1251.\" It seems so, looking at the handling of the rt_mutex_trylock()
1252.\" call in futex_lock_pi()
9732dd8b 1253.\" (Davidlohr also thinks so.)
c0091dd3 1254.\"
fea681da 1255.TP
5662f56a
MK
1256.BR EAGAIN
1257.RB ( FUTEX_LOCK_PI ,
aaec9032
MK
1258.BR FUTEX_TRYLOCK_PI ,
1259.BR FUTEX_CMP_REQUEUE_PI )
1260The futex owner thread ID of
1261.I uaddr
1262(for
1263.BR FUTEX_CMP_REQUEUE_PI :
1264.IR uaddr2 )
1265is about to exit,
5662f56a
MK
1266but has not yet handled the internal state cleanup.
1267Try again.
1268.TP
7a39e745
MK
1269.BR EDEADLK
1270.RB ( FUTEX_LOCK_PI ,
9732dd8b
MK
1271.BR FUTEX_TRYLOCK_PI ,
1272.BR FUTEX_CMP_REQUEUE_PI )
4b35dc5d 1273The futex word at
7a39e745
MK
1274.I uaddr
1275is already locked by the caller.
1276.TP
662c0da8 1277.BR EDEADLK
4c8cb0ff 1278.\" FIXME XXX I see that kernel/locking/rtmutex.c uses EDEADLK in some
d6bb5a38 1279.\" places, and EDEADLOCK in others. On almost all architectures
4c8cb0ff
MK
1280.\" these constants are synonymous. Is there a reason that both
1281.\" names are used?
d6bb5a38 1282.\" FIXME I reworded tglx's text somewhat; is the following okay?
662c0da8 1283.RB ( FUTEX_CMP_REQUEUE_PI )
4b35dc5d 1284While requeueing a waiter to the PI futex for the futex word at
662c0da8
MK
1285.IR uaddr2 ,
1286the kernel detected a deadlock.
1287.TP
fea681da 1288.B EFAULT
1ea901e8
MK
1289A required pointer argument (i.e.,
1290.IR uaddr ,
1291.IR uaddr2 ,
1292or
1293.IR timeout )
496df304 1294did not point to a valid user-space address.
fea681da 1295.TP
9f6c40c0 1296.B EINTR
e808bba0 1297A
9f6c40c0 1298.B FUTEX_WAIT
2674f781
MK
1299or
1300.B FUTEX_WAIT_BITSET
e808bba0 1301operation was interrupted by a signal (see
f529fd20
MK
1302.BR signal (7)).
1303In kernels before Linux 2.6.22, this error could also be returned for
1304on a spurious wakeup; since Linux 2.6.22, this no longer happens.
9f6c40c0 1305.TP
fea681da 1306.B EINVAL
180f97b7
MK
1307The operation in
1308.IR futex_op
1309is one of those that employs a timeout, but the supplied
fb2f4c27
MK
1310.I timeout
1311argument was invalid
1312.RI ( tv_sec
1313was less than zero, or
1314.IR tv_nsec
cabee29d 1315was not less than 1,000,000,000).
fb2f4c27
MK
1316.TP
1317.B EINVAL
0c74df0b 1318The operation specified in
025e1374 1319.IR futex_op
0c74df0b 1320employs one or both of the pointers
51ee94be 1321.I uaddr
a1f47699 1322and
0c74df0b
MK
1323.IR uaddr2 ,
1324but one of these does not point to a valid object\(emthat is,
1325the address is not four-byte-aligned.
51ee94be
MK
1326.TP
1327.B EINVAL
55cc422d
TG
1328.RB ( FUTEX_WAIT_BITSET ,
1329.BR FUTEX_WAKE_BITSET )
79c9b436
TG
1330The bitset supplied in
1331.IR val3
1332is zero.
1333.TP
1334.B EINVAL
2abcba67 1335.RB ( FUTEX_CMP_REQUEUE_PI )
add875c0
MK
1336.I uaddr
1337equals
1338.IR uaddr2
1339(i.e., an attempt was made to requeue to the same futex).
1340.TP
ff597681
MK
1341.BR EINVAL
1342.RB ( FUTEX_FD )
1343The signal number supplied in
1344.I val
1345is invalid.
1346.TP
6bac3b85 1347.B EINVAL
476debd7
MK
1348.RB ( FUTEX_WAKE ,
1349.BR FUTEX_WAKE_OP ,
1350.BR FUTEX_WAKE_BITSET ,
1351.BR FUTEX_REQUEUE ,
1352.BR FUTEX_CMP_REQUEUE )
1353The kernel detected an inconsistency between the user-space state at
1354.I uaddr
1355and the kernel state\(emthat is, it detected a waiter which waits in
1356.BR FUTEX_LOCK_PI
1357on
1358.IR uaddr .
1359.TP
1360.B EINVAL
a218ef20 1361.RB ( FUTEX_LOCK_PI ,
ce022f18
MK
1362.BR FUTEX_TRYLOCK_PI ,
1363.BR FUTEX_UNLOCK_PI )
a218ef20
MK
1364The kernel detected an inconsistency between the user-space state at
1365.I uaddr
1366and the kernel state.
ce022f18 1367This indicates either state corruption
d6bb5a38
MK
1368.\" FIXME tglx did not mention the "state corruption" case for
1369.\" FUTEX_UNLOCK_PI, but I have added it, since I'm estimating
1370.\" that it also applied for FUTEX_UNLOCK_PI.
1371.\" So, does that case also apply for FUTEX_UNLOCK_PI?
ce022f18 1372or that the kernel found a waiter on
a218ef20
MK
1373.I uaddr
1374which is waiting via
1375.BR FUTEX_WAIT
1376or
1377.BR FUTEX_WAIT_BITSET .
1378.TP
1379.B EINVAL
f9250b1a
MK
1380.RB ( FUTEX_CMP_REQUEUE_PI )
1381The kernel detected an inconsistency between the user-space state at
99c0041d
MK
1382.I uaddr2
1383and the kernel state;
1384that is, the kernel detected a waiter which waits via
1385.BR FUTEX_WAIT
1386.\" FIXME tglx did not mention FUTEX_WAIT_BITSET here,
1387.\" but should that not also be included here?
1388on
1389.IR uaddr2 .
1390.TP
1391.B EINVAL
1392.RB ( FUTEX_CMP_REQUEUE_PI )
1393The kernel detected an inconsistency between the user-space state at
f9250b1a
MK
1394.I uaddr
1395and the kernel state;
1396that is, the kernel detected a waiter which waits via
75299c8d 1397.BR FUTEX_WAIT
99c0041d 1398or
75299c8d 1399.BR FUTEX_WAIT_BITESET
f9250b1a
MK
1400on
1401.IR uaddr .
1402.TP
1403.B EINVAL
99c0041d 1404.RB ( FUTEX_CMP_REQUEUE_PI )
75299c8d
MK
1405The kernel detected an inconsistency between the user-space state at
1406.I uaddr
1407and the kernel state;
1408that is, the kernel detected a waiter which waits on
1409.I uaddr
1410via
1411.BR FUTEX_LOCK_PI
1412(instead of
1413.BR FUTEX_WAIT_REQUEUE_PI ).
99c0041d
MK
1414.TP
1415.B EINVAL
9786b3ca 1416.RB ( FUTEX_CMP_REQUEUE_PI )
f1d2171d 1417.\" FIXME XXX The following is a reworded version of Darren Hart's text.
9786b3ca
MK
1418.\" Please check that I did not introduce any errors.
1419An attempt was made to requeue a waiter to a futex other than that
1420specified by the matching
1421.B FUTEX_WAIT_REQUEUE_PI
1422call for that waiter.
1423.TP
1424.B EINVAL
f0c0d61c
MK
1425.RB ( FUTEX_CMP_REQUEUE_PI )
1426The
1427.I val
1428argument is not 1.
1429.TP
1430.B EINVAL
4832b48a 1431Invalid argument.
fea681da 1432.TP
a449c634
MK
1433.BR ENOMEM
1434.RB ( FUTEX_LOCK_PI ,
e34a8fb6
MK
1435.BR FUTEX_TRYLOCK_PI ,
1436.BR FUTEX_CMP_REQUEUE_PI )
a449c634
MK
1437The kernel could not allocate memory to hold state information.
1438.TP
fea681da 1439.B ENFILE
ff597681 1440.RB ( FUTEX_FD )
fea681da 1441The system limit on the total number of open files has been reached.
4701fc28
MK
1442.TP
1443.B ENOSYS
1444Invalid operation specified in
d33602c4 1445.IR futex_op .
9f6c40c0 1446.TP
4a7e5b05
MK
1447.B ENOSYS
1448The
1449.BR FUTEX_CLOCK_REALTIME
1450option was specified in
1afcee7c 1451.IR futex_op ,
4a7e5b05
MK
1452but the accompanying operation was neither
1453.BR FUTEX_WAIT_BITSET
1454nor
1455.BR FUTEX_WAIT_REQUEUE_PI .
1456.TP
a9dcb4d1
MK
1457.BR ENOSYS
1458.RB ( FUTEX_LOCK_PI ,
f2424fae 1459.BR FUTEX_TRYLOCK_PI ,
4945ff19 1460.BR FUTEX_UNLOCK_PI ,
4cf92894 1461.BR FUTEX_CMP_REQUEUE_PI ,
794bb106 1462.BR FUTEX_WAIT_REQUEUE_PI )
4b35dc5d 1463A run-time check determined that the operation is not available.
a2ebebcd 1464The PI futex operations are not implemented on all architectures and
077981d4 1465are not supported on some CPU variants.
a9dcb4d1 1466.TP
c7589177
MK
1467.BR EPERM
1468.RB ( FUTEX_LOCK_PI ,
dc2742a8
MK
1469.BR FUTEX_TRYLOCK_PI ,
1470.BR FUTEX_CMP_REQUEUE_PI )
04331c3f 1471The caller is not allowed to attach itself to the futex at
dc2742a8
MK
1472.I uaddr
1473(for
1474.BR FUTEX_CMP_REQUEUE_PI :
1475the futex at
1476.IR uaddr2 ).
c7589177
MK
1477(This may be caused by a state corruption in user space.)
1478.TP
76f347ba 1479.BR EPERM
87276709 1480.RB ( FUTEX_UNLOCK_PI )
4b35dc5d 1481The caller does not own the lock represented by the futex word.
76f347ba 1482.TP
0b0e4934
MK
1483.BR ESRCH
1484.RB ( FUTEX_LOCK_PI ,
9732dd8b
MK
1485.BR FUTEX_TRYLOCK_PI ,
1486.BR FUTEX_CMP_REQUEUE_PI )
0b0e4934
MK
1487.\" FIXME I reworded the following sentence a bit differently from
1488.\" tglx's formulation. Is it okay?
4b35dc5d 1489The thread ID in the futex word at
0b0e4934
MK
1490.I uaddr
1491does not exist.
1492.TP
360f773c
MK
1493.BR ESRCH
1494.RB ( FUTEX_CMP_REQUEUE_PI )
1495.\" FIXME I reworded the following sentence a bit differently from
1496.\" tglx's formulation. Is it okay?
4b35dc5d 1497The thread ID in the futex word at
360f773c
MK
1498.I uaddr2
1499does not exist.
1500.TP
9f6c40c0 1501.B ETIMEDOUT
4d85047f
MK
1502The operation in
1503.IR futex_op
1504employed the timeout specified in
1505.IR timeout ,
1506and the timeout expired before the operation completed.
70b06b90
MK
1507.\"
1508.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1509.\"
47297adb 1510.SH VERSIONS
a1d5f77c 1511.PP
81c9d87e
MK
1512Futexes were first made available in a stable kernel release
1513with Linux 2.6.0.
1514
4c8cb0ff
MK
1515Initial futex support was merged in Linux 2.5.7 but with different
1516semantics from what was described above.
52dee70e 1517A four-argument system call with the semantics
fd3fa7ef 1518described in this page was introduced in Linux 2.5.40.
11b520ed 1519In Linux 2.5.70, one argument
a1d5f77c 1520was added.
11b520ed 1521In Linux 2.6.7, a sixth argument was added\(emmessy, especially
a1d5f77c 1522on the s390 architecture.
47297adb 1523.SH CONFORMING TO
8382f16d 1524This system call is Linux-specific.
47297adb 1525.SH NOTES
baf0f1f4
MK
1526Glibc does not provide a wrapper for this system call; call it using
1527.BR syscall (2).
cf44281c
MK
1528
1529Various higher-level programming abstractions are implemented via futexes,
1530including POSIX threads mutexes and condition variables,
1531as well as POSIX semaphores.
74f58a64
MK
1532.\" TODO FIXME(Torvald) Above, we cite this section and claim it contains
1533.\" details on the synchronization semantics; add the C11 equivalents
1534.\" here (or whatever we find consensus for).
305cc415
MK
1535.\"
1536.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1537.\"
1538.SH EXAMPLE
1539.\" FIXME Is it worth having an example program?
1540.\" FIXME Anything obviously broken in the example program?
1541.\"
77da5feb 1542The program below demonstrates use of futexes in a program
305cc415
MK
1543where parent and child use a pair of futexes located inside a
1544shared anonymous mapping to synchronize access to a shared resource:
1545the terminal.
1546The two processes each write
1547.IR nloops
1548(a command-line argument that defaults to 5 if omitted)
1549messages to the terminal and employ a synchronization protocol
1550that ensures that they alternate in writing messages.
1551Upon running this program we see output such as the following:
1552
1553.in +4n
1554.nf
1555$ \fB./futex_demo\fP
1556Parent (18534) 0
1557Child (18535) 0
1558Parent (18534) 1
1559Child (18535) 1
1560Parent (18534) 2
1561Child (18535) 2
1562Parent (18534) 3
1563Child (18535) 3
1564Parent (18534) 4
1565Child (18535) 4
1566.fi
1567.in
1568.SS Program source
1569\&
1570.nf
1571/* futex_demo.c
1572
1573 Usage: futex_demo [nloops]
1574 (Default: 5)
1575
1576 Demonstrate the use of futexes in a program where parent and child
1577 use a pair of futexes located inside a shared anonymous mapping to
1578 synchronize access to a shared resource: the terminal. The two
1579 processes each write \(aqnum\-loops\(aq messages to the terminal and employ
1580 a synchronization protocol that ensures that they alternate in
1581 writing messages.
1582*/
1583#define _GNU_SOURCE
1584#include <stdio.h>
1585#include <errno.h>
1586#include <stdlib.h>
1587#include <unistd.h>
1588#include <sys/wait.h>
1589#include <sys/mman.h>
1590#include <sys/syscall.h>
1591#include <linux/futex.h>
1592#include <sys/time.h>
1593
1594#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
1595 } while (0)
1596
1597static int *futex1, *futex2, *iaddr;
1598
1599static int
1600futex(int *uaddr, int futex_op, int val,
1601 const struct timespec *timeout, int *uaddr2, int val3)
1602{
1603 return syscall(SYS_futex, uaddr, futex_op, val,
1604 timeout, uaddr, val3);
1605}
1606
1607/* Acquire the futex pointed to by \(aqfutexp\(aq: wait for its value to
1608 become 1, and then set the value to 0. */
1609
1610static void
1611fwait(int *futexp)
1612{
1613 int s;
1614
1615 /* __sync_bool_compare_and_swap(ptr, oldval, newval) is a gcc
1616 built\-in function. It atomically performs the equivalent of:
1617
1618 if (*ptr == oldval)
1619 *ptr = newval;
1620
1621 It returns true if the test yielded true and *ptr was updated.
1622 The alternative here would be to employ the equivalent atomic
1623 machine\-language instructions. For further information, see
1624 the GCC Manual. */
1625
305cc415 1626 while (1) {
83e80dda 1627
63ad44cb 1628 /* Is the futex available? */
83e80dda 1629
305cc415
MK
1630 if (__sync_bool_compare_and_swap(futexp, 1, 0))
1631 break; /* Yes */
1632
63ad44cb 1633 /* Futex is not available; wait */
83e80dda 1634
63ad44cb
HS
1635 s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
1636 if (s == \-1 && errno != EAGAIN)
1637 errExit("futex\-FUTEX_WAIT");
305cc415
MK
1638 }
1639}
1640
1641/* Release the futex pointed to by \(aqfutexp\(aq: if the futex currently
1642 has the value 0, set its value to 1 and the wake any futex waiters,
1643 so that if the peer is blocked in fpost(), it can proceed. */
1644
1645static void
1646fpost(int *futexp)
1647{
1648 int s;
1649
1650 /* __sync_bool_compare_and_swap() was described in comments above */
1651
1652 if (__sync_bool_compare_and_swap(futexp, 0, 1)) {
1653
1654 s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);
1655 if (s == \-1)
1656 errExit("futex\-FUTEX_WAKE");
1657 }
1658}
1659
1660int
1661main(int argc, char *argv[])
1662{
1663 pid_t childPid;
1664 int j, nloops;
1665
1666 setbuf(stdout, NULL);
1667
1668 nloops = (argc > 1) ? atoi(argv[1]) : 5;
1669
1670 /* Create a shared anonymous mapping that will hold the futexes.
1671 Since the futexes are being shared between processes, we
1672 subsequently use the "shared" futex operations (i.e., not the
1673 ones suffixed "_PRIVATE") */
1674
1675 iaddr = mmap(NULL, sizeof(int) * 2, PROT_READ | PROT_WRITE,
1676 MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
1677 if (iaddr == MAP_FAILED)
1678 errExit("mmap");
1679
1680 futex1 = &iaddr[0];
1681 futex2 = &iaddr[1];
1682
1683 *futex1 = 0; /* State: unavailable */
1684 *futex2 = 1; /* State: available */
1685
1686 /* Create a child process that inherits the shared anonymous
35764662 1687 mapping */
305cc415
MK
1688
1689 childPid = fork();
92a46690 1690 if (childPid == \-1)
305cc415
MK
1691 errExit("fork");
1692
1693 if (childPid == 0) { /* Child */
1694 for (j = 0; j < nloops; j++) {
1695 fwait(futex1);
1696 printf("Child (%ld) %d\\n", (long) getpid(), j);
1697 fpost(futex2);
1698 }
1699
1700 exit(EXIT_SUCCESS);
1701 }
1702
1703 /* Parent falls through to here */
1704
1705 for (j = 0; j < nloops; j++) {
1706 fwait(futex2);
1707 printf("Parent (%ld) %d\\n", (long) getpid(), j);
1708 fpost(futex1);
1709 }
1710
1711 wait(NULL);
1712
1713 exit(EXIT_SUCCESS);
1714}
1715.fi
47297adb 1716.SH SEE ALSO
4c222281 1717.ad l
9913033c 1718.BR get_robust_list (2),
d806bc05 1719.BR restart_syscall (2),
14d8dd3b 1720.BR futex (7)
fea681da 1721.PP
f5ad572f
MK
1722The following kernel source files:
1723.IP * 2
1724.I Documentation/pi-futex.txt
1725.IP *
1726.I Documentation/futex-requeue-pi.txt
1727.IP *
1728.I Documentation/locking/rt-mutex.txt
1729.IP *
1730.I Documentation/locking/rt-mutex-design.txt
8fe019c7
MK
1731.IP *
1732.I Documentation/robust-futex-ABI.txt
43b99089 1733.PP
4c222281 1734Franke, H., Russell, R., and Kirwood, M., 2002.
52087dd3 1735\fIFuss, Futexes and Furwocks: Fast Userlevel Locking in Linux\fP
4c222281 1736(from proceedings of the Ottawa Linux Symposium 2002),
9b936e9e 1737.br
608bf950
SK
1738.UR http://kernel.org\:/doc\:/ols\:/2002\:/ols2002-pages-479-495.pdf
1739.UE
f42eb21b 1740
4c222281 1741Hart, D., 2009. \fIA futex overview and update\fP,
2ed26199
MK
1742.UR http://lwn.net/Articles/360699/
1743.UE
1744
4c222281 1745Hart, D. and Guniguntala, D., 2009.
0483b6cc 1746\fIRequeue-PI: Making Glibc Condvars PI-Aware\fP
4c222281 1747(from proceedings of the 2009 Real-Time Linux Workshop),
0483b6cc
MK
1748.UR http://lwn.net/images/conf/rtlws11/papers/proc/p10.pdf
1749.UE
1750
4c222281 1751Drepper, U., 2011. \fIFutexes Are Tricky\fP,
f42eb21b
MK
1752.UR http://www.akkadia.org/drepper/futex.pdf
1753.UE
9b936e9e
MK
1754.PP
1755Futex example library, futex-*.tar.bz2 at
1756.br
a605264d 1757.UR ftp://ftp.kernel.org\:/pub\:/linux\:/kernel\:/people\:/rusty/
608bf950 1758.UE
34f14794
MK
1759.\"
1760.\" FIXME Are there any other resources that should be listed
1761.\" in the SEE ALSO section?
74f58a64 1762.\" FIXME(Torvald) We should probably refer to the glibc code here, in
4c8cb0ff
MK
1763.\" particular the glibc-internal futex wrapper functions that are
1764.\" WIP, and the generic pthread_mutex_t and perhaps condvar
1765.\" implementations.