summaryrefslogtreecommitdiffstats
path: root/man7/futex.7
diff options
context:
space:
mode:
Diffstat (limited to 'man7/futex.7')
-rw-r--r--man7/futex.724
1 files changed, 12 insertions, 12 deletions
diff --git a/man7/futex.7 b/man7/futex.7
index 233933b..52af91f 100644
--- a/man7/futex.7
+++ b/man7/futex.7
@@ -6,7 +6,7 @@
.\"
.\" SPDX-License-Identifier: MIT
.\"
-.TH futex 7 2022-10-30 "Linux man-pages 6.05.01"
+.TH futex 7 2023-10-31 "Linux man-pages 6.7"
.SH NAME
futex \- fast user-space locking
.SH SYNOPSIS
@@ -20,24 +20,24 @@ locking and semaphores.
Futexes are very basic and lend themselves well for building higher-level
locking abstractions such as
mutexes, condition variables, read-write locks, barriers, and semaphores.
-.PP
+.P
Most programmers will in fact not be using futexes directly but will
instead rely on system libraries built on them,
such as the Native POSIX Thread Library (NPTL) (see
.BR pthreads (7)).
-.PP
+.P
A futex is identified by a piece of memory which can be
shared between processes or threads.
In these different processes, the futex need not have identical addresses.
In its bare form, a futex has semaphore semantics;
it is a counter that can be incremented and decremented atomically;
processes can wait for the value to become positive.
-.PP
+.P
Futex operation occurs entirely in user space for the noncontended case.
The kernel is involved only to arbitrate the contended case.
As any sane design will strive for noncontention,
futexes are also optimized for this situation.
-.PP
+.P
In its bare form, a futex is an aligned integer which is
touched only by atomic assembler instructions.
This integer is four bytes long on all platforms.
@@ -50,13 +50,13 @@ Any futex operation starts in user space,
but it may be necessary to communicate with the kernel using the
.BR futex (2)
system call.
-.PP
+.P
To "up" a futex, execute the proper assembler instructions that
will cause the host CPU to atomically increment the integer.
Afterward, check if it has in fact changed from 0 to 1, in which case
there were no waiters and the operation is done.
This is the noncontended case which is fast and should be common.
-.PP
+.P
In the contended case, the atomic increment changed the counter
from \-1 (or some other negative number).
If this is detected, there are waiters.
@@ -64,7 +64,7 @@ User space should now set the counter to 1 and instruct the
kernel to wake up any waiters using the
.B FUTEX_WAKE
operation.
-.PP
+.P
Waiting on a futex, to "down" it, is the reverse operation.
Atomically decrement the counter and check if it changed to 0,
in which case the operation is done and the futex was uncontended.
@@ -73,7 +73,7 @@ and request that the kernel wait for another process to up the futex.
This is done using the
.B FUTEX_WAIT
operation.
-.PP
+.P
The
.BR futex (2)
system call can optionally be passed a timeout specifying how long
@@ -95,12 +95,12 @@ abstraction for end users.
Implementors are expected to be assembly literate and to have read
the sources of the futex user-space library referenced
below.
-.PP
+.P
This man page illustrates the most common use of the
.BR futex (2)
primitives; it is by no means the only one.
.\" .SH AUTHORS
-.\" .PP
+.\" .P
.\" Futexes were designed and worked on by Hubertus Franke
.\" (IBM Thomas J. Watson Research Center),
.\" Matthew Kirkwood, Ingo Molnar (Red Hat) and
@@ -113,7 +113,7 @@ primitives; it is by no means the only one.
.BR set_robust_list (2),
.BR set_tid_address (2),
.BR pthreads (7)
-.PP
+.P
.I Fuss, Futexes and Furwocks: Fast Userlevel Locking in Linux
(proceedings of the Ottawa Linux Symposium 2002),
futex example library, futex-*.tar.bz2