# SOME DESCRIPTIVE TITLE # Copyright (C) YEAR Free Software Foundation, Inc. # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2026-06-05 06:25+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #. type: TH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "futex" msgstr "" #. type: TH #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "2026-02-14" msgstr "" #. type: TH #: archlinux debian-unstable #, no-wrap msgid "Linux man-pages 6.18" msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "NAME" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "futex - fast user-space locking" msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "LIBRARY" msgstr "" #. type: Plain text #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Standard C library (I,\\ I<-lc>)" msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SYNOPSIS" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "B<#include Elinux/futex.hE> /* Definition of B constants */\n" "B<#include Esys/syscall.hE> /* Definition of B constants */\n" "B<#include Eunistd.hE>\n" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "BIB<, int >IB<, ...);>\n" msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "DESCRIPTION" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B() system call provides a method for waiting until a certain " "condition becomes true. It is typically used as a blocking construct in the " "context of shared-memory synchronization. When using futexes, the majority " "of the synchronization operations are performed in user space. A user-space " "program employs the B() system call only when it is likely that the " "program has to block for a longer time until the condition becomes true. " "Other B() operations can be used to wake any processes or threads " "waiting for a particular condition." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A futex is a 32-bit value\\[em]referred to below as a I\\" "[em]whose address is supplied to the B() system call. (Futexes are " "32 bits in size on all platforms, including 64-bit systems.) All futex " "operations are governed by this value. In order to share a futex between " "processes, the futex is placed in a region of shared memory, created using " "(for example) B(2) or B(2). (Thus, the futex word may have " "different virtual addresses in different processes, but these addresses all " "refer to the same location in physical memory.) In a multithreaded program, " "it is sufficient to place the futex word in a global variable shared by all " "threads." msgstr "" # #. #-#-#-#-# archlinux: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# debian-trixie: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# debian-unstable: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# fedora-44: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# fedora-rawhide: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# mageia-cauldron: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Notes from Darren Hart (Dec 2015): #. Totally ordered with respect futex operations refers to semantics #. of the ACQUIRE/RELEASE operations and how they impact ordering of #. memory reads and writes. The kernel futex operations are protected #. by spinlocks, which ensure that all operations are serialized #. with respect to one another. #. This is a lot to attempt to define in this document. Perhaps a #. reference to linux/Documentation/memory-barriers.txt as a footnote #. would be sufficient? Or perhaps for this manual, "serialized" would #. be sufficient, with a footnote regarding "totally ordered" and a #. pointer to the memory-barrier documentation? #. FIXME(Torvald Riegel): #. Eventually we want to have some text in NOTES to satisfy #. the reference in the following sentence #. See NOTES for a detailed specification of #. the synchronization semantics. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "When executing a futex operation that requests to block a thread, the kernel " "will block only if the futex word has the value that the calling thread " "supplied (as one of the arguments of the B() call) as the expected " "value of the futex word. The loading of the futex word's value, the " "comparison of that value with the expected value, and the actual blocking " "will happen atomically and will be totally ordered with respect to " "concurrent operations performed by other threads on the same futex word. " "Thus, the futex word is used to connect the synchronization in user space " "with the implementation of blocking by the kernel. Analogously to an atomic " "compare-and-exchange operation that potentially changes shared memory, " "blocking via a futex is an atomic compare-and-block operation." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "One use of futexes is for implementing locks. The state of the lock (i.e., " "acquired or not acquired) can be represented as an atomically accessed flag " "in shared memory. In the uncontended case, a thread can access or modify " "the lock state with atomic instructions, for example atomically changing it " "from not acquired to acquired using an atomic compare-and-exchange " "instruction. (Such instructions are performed entirely in user mode, and " "the kernel maintains no information about the lock state.) On the other " "hand, a thread may be unable to acquire a lock because it is already " "acquired by another thread. It then may pass the lock's flag as a futex " "word and the value representing the acquired state as the expected value to " "a B() wait operation. This B() operation will block if and " "only if the lock is still acquired (i.e., the value in the futex word still " "matches the \"acquired state\"). When releasing the lock, a thread has to " "first reset the lock state to not acquired and then execute a futex " "operation that wakes threads blocked on the lock flag used as a futex word " "(this can be further optimized to avoid unnecessary wake-ups). See " "B(7) for more detail on how to use futexes." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Besides the basic wait and wake-up futex functionality, there are further " "futex operations aimed at supporting more complex use cases." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Note that no explicit initialization or destruction is necessary to use " "futexes; the kernel maintains a futex (i.e., the kernel-internal " "implementation artifact) only while operations such as " "B(2const) are being performed on a particular futex word." msgstr "" #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Arguments" msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The I argument points to the futex word. On all platforms, futexes " "are four-byte integers that must be aligned on a four-byte boundary. The " "operation to perform on the futex is specified in the I argument." msgstr "" #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Futex operations" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The I argument consists of two parts: a command that specifies the " "operation to be performed, bitwise ORed with zero or more options that " "modify the behavior of the operation. The options that may be included in " "I are as follows:" msgstr "" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B (since Linux 2.6.22)" msgstr "" #. commit 34f01cc1f512fa783302982776895c73714ebbc2 #. I.e., It allows the kernel choose the fast path for validating #. the user-space address and avoids expensive VMA lookups, #. taking reference counts on file backing store, and so on. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This option bit can be employed with all futex operations. It tells the " "kernel that the futex is process-private and not shared with another process " "(i.e., it is being used for synchronization only between threads of the same " "process). This allows the kernel to make some additional performance " "optimizations." msgstr "" #. #-#-#-#-# archlinux: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD(2const), for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# debian-trixie: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD, for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# debian-unstable: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD(2const), for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# fedora-44: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD, for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# fedora-rawhide: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD, for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# mageia-cauldron: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD(2const), for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD(2const), for which the "private" flag was #. meaningless #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. except the obsolete FUTEX_FD(2const), for which the "private" flag was #. meaningless #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "As a convenience, Ilinux/futex.hE> defines a set of constants with " "the suffix B<_PRIVATE> that are equivalents of all of the operations listed " "below, but with the B ORed into the constant value. " "Thus, there are B, B, and so on." msgstr "" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B (since Linux 2.6.28)" msgstr "" #. commit 1acdac104668a0834cfa267de9946fac7764d486 #. commit 337f13046ff03717a9e99675284a817527440a49 #. commit bf22a6976897977b0a3f1aeba6823c959fc4fdae #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "This option bit can be employed only with the B(2const), " "B(2const), (since Linux 4.5) B(2const), " "and (since Linux 5.14) B(2const) operations." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If this option is set, the kernel measures the I against the " "B clock." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If this option is not set, the kernel measures the I against the " "B clock." msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "The operation specified in I is one of the following:" msgstr "" #. type: TP #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Priority-inheritance futexes" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Linux supports priority-inheritance (PI) futexes in order to handle priority-" "inversion problems that can be encountered with normal futex locks. " "Priority inversion is the problem that occurs when a high-priority task is " "blocked waiting to acquire a lock held by a low-priority task, while tasks " "at an intermediate priority continuously preempt the low-priority task from " "the CPU. Consequently, the low-priority task makes no progress toward " "releasing the lock, and the high-priority task remains blocked." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Priority inheritance is a mechanism for dealing with the priority-inversion " "problem. With this mechanism, when a high-priority task becomes blocked by " "a lock held by a low-priority task, the priority of the low-priority task is " "temporarily raised to that of the high-priority task, so that it is not " "preempted by any intermediate level tasks, and can thus make progress toward " "releasing the lock. To be effective, priority inheritance must be " "transitive, meaning that if a high-priority task blocks on a lock held by a " "lower-priority task that is itself blocked by a lock held by another " "intermediate-priority task (and so on, for chains of arbitrary length), then " "both of those tasks (or more generally, all of the tasks in a lock chain) " "have their priorities raised to be the same as the high-priority task." msgstr "" # #. #-#-#-#-# archlinux: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# debian-trixie: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# debian-unstable: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# fedora-44: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# fedora-rawhide: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# mageia-cauldron: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. Quoting Darren Hart: #. These opcodes paired with the PI futex value policy (described below) #. defines a "futex" as PI aware. These were created very specifically #. in support of PI pthread_mutexes, so it makes a lot more sense to #. talk about a PI aware pthread_mutex, than a PI aware futex, since #. there is a lot of policy and scaffolding that has to be built up #. around it to use it properly (this is what a PI pthread_mutex is). #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "From a user-space perspective, what makes a futex PI-aware is a policy " "agreement (described below) between user space and the kernel about the " "value of the futex word, coupled with the use of the PI-futex operations " "described below. (Unlike the other futex operations described above, the PI-" "futex operations are designed for the implementation of very specific IPC " "mechanisms.)" msgstr "" #. mtk: The following text is drawn from the Hart/Guniguntala paper #. (listed in SEE ALSO), but I have reworded some pieces #. significantly. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The PI-futex operations described below differ from the other futex " "operations in that they impose policy on the use of the value of the futex " "word:" msgstr "" #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\[bu]" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "If the lock is not acquired, the futex word's value shall be 0." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the lock is acquired, the futex word's value shall be the thread ID (TID; " "see B(2)) of the owning thread." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the lock is owned and there are threads contending for the lock, then the " "B bit shall be set in the futex word's value; in other words, " "this value is:" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "FUTEX_WAITERS | TID\n" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "(Note that is invalid for a PI futex word to have no owner and " "B set.)" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "With this policy in place, a user-space application can acquire an " "unacquired lock or release a lock using atomic instructions executed in user " "mode (e.g., a compare-and-swap operation such as I on the x86 " "architecture). Acquiring a lock simply consists of using compare-and-swap " "to atomically set the futex word's value to the caller's TID if its previous " "value was 0. Releasing a lock requires using compare-and-swap to set the " "futex word's value to 0 if the previous value was the expected TID." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "If a futex is already acquired (i.e., has a nonzero value), waiters must " "employ the B(2const) or B(2const) " "operations to acquire the lock. If other threads are waiting for the lock, " "then the B bit is set in the futex value; in this case, the " "lock owner must employ the B(2const) operation to release " "the lock." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the cases where callers are forced into the kernel (i.e., required to " "perform a B() call), they then deal directly with a so-called RT-" "mutex, a kernel locking mechanism which implements the required priority-" "inheritance semantics. After the RT-mutex is acquired, the futex value is " "updated accordingly, before the calling thread returns to user space." msgstr "" #. #-#-#-#-# archlinux: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# debian-trixie: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# debian-unstable: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# fedora-44: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# fedora-rawhide: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# mageia-cauldron: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. If there are multiple waiters on a pi futex then a wake pi operation #. will wake the first waiter and hand over the lock to this waiter. This #. includes handing over the rtmutex which represents the futex in the #. kernel. The strict requirement is that the futex owner and the rtmutex #. owner must be the same, except for the update period which is #. serialized by the futex internal locking. That means the kernel must #. update the user-space value prior to returning to user space #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "It is important to note that the kernel will update the futex word's value " "prior to returning to user space. (This prevents the possibility of the " "futex word's value ending up in an invalid state, such as having an owner " "but the value being 0, or having waiters but not having the B " "bit set.)" msgstr "" #. #-#-#-#-# archlinux: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# debian-trixie: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# debian-unstable: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# fedora-44: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# fedora-rawhide: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# mageia-cauldron: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: futex.2.pot (PACKAGE VERSION) #-#-#-#-# #. tglx (July 2015): #. The FUTEX_OWNER_DIED bit can also be set on uncontended futexes, where #. the kernel has no state associated. This happens via the robust futex #. mechanism. In that case the futex value will be set to #. FUTEX_OWNER_DIED. The robust futex mechanism is also available for non #. PI futexes. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If a futex has an associated RT-mutex in the kernel (i.e., there are blocked " "waiters) and the owner of the futex/RT-mutex dies unexpectedly, then the " "kernel cleans up the RT-mutex and hands it over to the next waiter. This in " "turn requires that the user-space value is updated accordingly. To indicate " "that this is required, the kernel sets the B bit in the " "futex word along with the thread ID of the new owner. User space can detect " "this situation via the presence of the B bit and is then " "responsible for cleaning up the stale state left over by the dead owner." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "PI futexes are operated on by specifying one of the values listed below in " "I. Note that the PI futex operations must be used as paired operations " "and are subject to some additional requirements:" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "B(2const), B(2const), and " "B(2const) pair with B(2const). " "B(2const) must be called only on a futex owned by the " "calling thread, as defined by the value policy, otherwise the error B " "results." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "B(2const) pairs with " "B(2const). This must be performed from a non-PI futex " "to a distinct PI futex (or the error B results). Additionally, the " "number of waiters to be woken must be 1 (or the error B results)." msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The PI futex operations are as follows:" msgstr "" #. type: TP #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" #. type: TQ #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "B(2const)" msgstr "" # # # # # #. Darren Hart notes that a patch to allow glibc to fully support #. PI-aware pthreads condition variables has not yet been accepted into #. glibc. The story is complex, and can be found at #. https://sourceware.org/bugzilla/show_bug.cgi?id=11588 #. Darren notes that in the meantime, the patch is shipped with various #. PREEMPT_RT-enabled Linux systems. #. Related to the preceding, Darren proposed that somewhere, man-pages #. should document the following point: #. While the Linux kernel, since Linux 2.6.31, supports requeueing of #. priority-inheritance (PI) aware mutexes via the #. FUTEX_WAIT_REQUEUE_PI and FUTEX_CMP_REQUEUE_PI futex operations, #. the glibc implementation does not yet take full advantage of this. #. Specifically, the condvar internal data lock remains a non-PI aware #. mutex, regardless of the type of the pthread_mutex associated with #. the condvar. This can lead to an unbounded priority inversion on #. the internal data lock even when associating a PI aware #. pthread_mutex with a condvar during a pthread_cond*_wait #. operation. For this reason, it is not recommended to rely on #. priority inheritance when using pthread condition variables. #. The problem is that the obvious location for this text is #. the pthread_cond*wait(3) man page. However, such a man page #. does not currently exist. #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The B(2const) and B(2const) " "were added to support a fairly specific use case: support for priority-" "inheritance-aware POSIX threads condition variables. The idea is that these " "operations should always be paired, in order to ensure that user space and " "the kernel remain in sync. Thus, in the B(2const) " "operation, the user-space application pre-specifies the target of the " "requeue that takes place in the B(2const) operation." msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "RETURN VALUE" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "On error, -1 is returned, and I is set to indicate the error." msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "The return value on success depends on the operation." msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "ERRORS" msgstr "" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "No read access to the memory of a futex word." msgstr "" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "I did not point to a valid user-space address." msgstr "" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "I does not point to a valid object\\[em]that is, the address is not " "four-byte-aligned." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Invalid argument." msgstr "" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "Invalid operation specified in I." msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The B option was specified in I, but the " "accompanying operation was neither B(2const), " "B(2const), nor B(2const)." msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "STANDARDS" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Linux." msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "HISTORY" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Linux 2.6.0." msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Initial futex support was merged in Linux 2.5.7 but with different semantics " "from what was described above. A four-argument system call with the " "semantics described in this page was introduced in Linux 2.5.40. A fifth " "argument was added in Linux 2.5.70, and a sixth argument was added in Linux " "2.6.7." msgstr "" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "EXAMPLES" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The program below demonstrates use of futexes in a program where a parent " "process and a child process use a pair of futexes located inside a shared " "anonymous mapping to synchronize access to a shared resource: the terminal. " "The two processes each write I (a command-line argument that " "defaults to 5 if omitted) messages to the terminal and employ a " "synchronization protocol that ensures that they alternate in writing " "messages. Upon running this program we see output such as the following:" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "$B< ./futex_demo>;\n" "Parent (18534) 0\n" "Child (18535) 0\n" "Parent (18534) 1\n" "Child (18535) 1\n" "Parent (18534) 2\n" "Child (18535) 2\n" "Parent (18534) 3\n" "Child (18535) 3\n" "Parent (18534) 4\n" "Child (18535) 4\n" msgstr "" #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Program source" msgstr "" #. type: Plain text #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "/* futex_demo.c\n" "\\&\n" " Usage: futex_demo [nloops]\n" " (Default: 5)\n" "\\&\n" " Demonstrate the use of futexes in a program where parent and child\n" " use a pair of futexes located inside a shared anonymous mapping to\n" " synchronize access to a shared resource: the terminal. The two\n" " processes each write \\[aq]num-loops\\[aq] messages to the terminal and employ\n" " a synchronization protocol that ensures that they alternate in\n" " writing messages.\n" "*/\n" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Elinux/futex.hE\n" "#include Estdatomic.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Esys/mman.hE\n" "#include Esys/syscall.hE\n" "#include Esys/time.hE\n" "#include Esys/wait.hE\n" "#include Eunistd.hE\n" "\\&\n" "static uint32_t *futex1, *futex2, *iaddr;\n" "\\&\n" "static int\n" "futex(uint32_t *uaddr, int op, uint32_t val,\n" " const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)\n" "{\n" " return syscall(SYS_futex, uaddr, op, val,\n" " timeout, uaddr2, val3);\n" "}\n" "\\&\n" "/* Acquire the futex pointed to by \\[aq]futexp\\[aq]: wait for its value to\n" " become 1, and then set the value to 0. */\n" "\\&\n" "static void\n" "fwait(uint32_t *futexp)\n" "{\n" " long s;\n" " const uint32_t one = 1;\n" "\\&\n" " /* atomic_compare_exchange_strong(ptr, oldval, newval)\n" " atomically performs the equivalent of:\n" "\\&\n" " if (*ptr == *oldval)\n" " *ptr = newval;\n" "\\&\n" " It returns true if the test yielded true and *ptr was updated. */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Is the futex available? */\n" " if (atomic_compare_exchange_strong(futexp, &one, 0))\n" " break; /* Yes */\n" "\\&\n" " /* Futex is not available; wait. */\n" "\\&\n" " s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);\n" " if (s == -1 && errno != EAGAIN)\n" " err(EXIT_FAILURE, \"futex-FUTEX_WAIT\");\n" " }\n" "}\n" "\\&\n" "/* Release the futex pointed to by \\[aq]futexp\\[aq]: if the futex currently\n" " has the value 0, set its value to 1 and then wake any futex waiters,\n" " so that if the peer is blocked in fwait(), it can proceed. */\n" "\\&\n" "static void\n" "fpost(uint32_t *futexp)\n" "{\n" " long s;\n" " const uint32_t zero = 0;\n" "\\&\n" " /* atomic_compare_exchange_strong() was described\n" " in comments above. */\n" "\\&\n" " if (atomic_compare_exchange_strong(futexp, &zero, 1)) {\n" " s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);\n" " if (s == -1)\n" " err(EXIT_FAILURE, \"futex-FUTEX_WAKE\");\n" " }\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " pid_t childPid;\n" " unsigned int nloops;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " nloops = (argc E 1) ? atoi(argv[1]) : 5;\n" "\\&\n" " /* Create a shared anonymous mapping that will hold the futexes.\n" " Since the futexes are being shared between processes, we\n" " subsequently use the \"shared\" futex operations (i.e., not the\n" " ones suffixed \"_PRIVATE\"). */\n" "\\&\n" " iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,\n" " MAP_ANONYMOUS | MAP_SHARED, -1, 0);\n" " if (iaddr == MAP_FAILED)\n" " err(EXIT_FAILURE, \"mmap\");\n" "\\&\n" " futex1 = &iaddr[0];\n" " futex2 = &iaddr[1];\n" "\\&\n" " *futex1 = 0; /* State: unavailable */\n" " *futex2 = 1; /* State: available */\n" "\\&\n" " /* Create a child process that inherits the shared anonymous\n" " mapping. */\n" "\\&\n" " childPid = fork();\n" " if (childPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (childPid == 0) { /* Child */\n" " for (unsigned int j = 0; j E nloops; j++) {\n" " fwait(futex1);\n" " printf(\"Child (%jd) %u\\[rs]n\", (intmax_t) getpid(), j);\n" " fpost(futex2);\n" " }\n" "\\&\n" " exit(EXIT_SUCCESS);\n" " }\n" "\\&\n" " /* Parent falls through to here. */\n" "\\&\n" " for (unsigned int j = 0; j E nloops; j++) {\n" " fwait(futex2);\n" " printf(\"Parent (%jd) %u\\[rs]n\", (intmax_t) getpid(), j);\n" " fpost(futex1);\n" " }\n" "\\&\n" " wait(NULL);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" #. SRC END #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SEE ALSO" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "B(2), B(2), " "B(3), B(7), B(7)" msgstr "" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The following kernel source files:" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "I" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "I" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "I" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "I" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "I" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "Franke, H., Russell, R., and Kirwood, M., 2002." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "E<.UR http:\\://kernel.org/\\:doc/\\:ols/\\:2002/\\:ols2002-" "pages-479-495.pdf> I E<.UE> (from proceedings of the Ottawa Linux Symposium 2002)." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Hart, D., 2009. E<.UR http:\\://lwn.net/\\:Articles/\\:360699/> I E<.UE .>" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Hart, D.\\& and Guniguntala, D., 2009. E<.UR http:\\://lwn.net/\\:images/" "\\:conf/\\:rtlws11/\\:papers/\\:proc/\\:p10.pdf> I E<.UE> (from proceedings of the 2009 Real-Time Linux " "Workshop)." msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Drepper, U., 2011. E<.UR http:\\://www.akkadia.org/\\:drepper/\\:futex.pdf> " "I E<.UE .>" msgstr "" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Futex example library, E<.UR https:\\://mirrors.kernel.org/\\:pub/\\:linux/" "\\:kernel/\\:people/\\:rusty/> futex-*.tar.bz2 E<.UE .>" msgstr "" #. type: TH #: debian-trixie #, no-wrap msgid "2024-06-15" msgstr "" #. type: TH #: debian-trixie #, no-wrap msgid "Linux man-pages 6.9.1" msgstr "" #. type: Plain text #: debian-trixie msgid "Standard C library (I, I<-lc>)" msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "B<#include Elinux/futex.hE> /* Definition of B constants */\n" "B<#include Esys/syscall.hE> /* Definition of B constants */\n" "B<#include Eunistd.hE>\n" msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "BIB<, int >IB<, uint32_t >IB<,>\n" "B< const struct timespec *>IB<,>I< > /* or: BIB< */>\n" "B< uint32_t *>IB<, uint32_t >IB<);>\n" msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "I: glibc provides no wrapper for B(), necessitating the use of " "B(2)." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "Note that no explicit initialization or destruction is necessary to use " "futexes; the kernel maintains a futex (i.e., the kernel-internal " "implementation artifact) only while operations such as B, " "described below, are being performed on a particular futex word." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "The I argument points to the futex word. On all platforms, futexes " "are four-byte integers that must be aligned on a four-byte boundary. The " "operation to perform on the futex is specified in the I argument; " "I is a value whose meaning and purpose depends on I." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "The remaining arguments (I, I, and I) are required " "only for certain of the futex operations described below. Where one of " "these arguments is not required, it is ignored." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "For several blocking operations, the I argument is a pointer to a " "I structure that specifies a timeout for the operation. However, " "notwithstanding the prototype shown above, for some operations, the least " "significant four bytes of this argument are instead used as an integer whose " "meaning is determined by the operation. For these operations, the kernel " "casts the I value first to I, then to I, " "and in the remainder of this page, this argument is referred to as I " "when interpreted in this fashion." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "Where it is required, the I argument is a pointer to a second futex " "word that is employed by the operation." msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "The interpretation of the final integer argument, I, depends on the " "operation." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "The I argument consists of two parts: a command that specifies the " "operation to be performed, bitwise ORed with zero or more options that " "modify the behaviour of the operation. The options that may be included in " "I are as follows:" msgstr "" #. commit 1acdac104668a0834cfa267de9946fac7764d486 #. commit 337f13046ff03717a9e99675284a817527440a49 #. commit bf22a6976897977b0a3f1aeba6823c959fc4fdae #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "This option bit can be employed only with the B, " "B, (since Linux 4.5) B, and (since Linux " "5.14) B operations." msgstr "" # #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "The operation specified in I is one of the following:" msgstr "" #. type: TP #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "B (since Linux 2.6.0)" msgstr "" #. Strictly speaking, since some time in Linux 2.5.x #. FIXME: Torvald, I think we may need to add some explanation of #. "totally ordered" here. #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "This operation tests that the value at the futex word pointed to by the " "address I still contains the expected value I, and if so, then " "sleeps waiting for a B operation on the futex word. The load of " "the value of the futex word is an atomic memory access (i.e., using atomic " "machine instructions of the respective architecture). This load, the " "comparison with the expected value, and starting to sleep are performed " "atomically and totally ordered with respect to other futex operations on the " "same futex word. If the thread starts to sleep, it is considered a waiter " "on this futex word. If the futex value does not match I, then the call " "fails immediately with the error B." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "The purpose of the comparison with the expected value is to prevent lost " "wake-ups. If another thread changed the value of the futex word after the " "calling thread decided to block based on the prior value, and if the other " "thread executed a B operation (or similar wake-up) after the " "value change and before this B operation, then the calling " "thread will observe the value change and will not start to sleep." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "If the I is not NULL, the structure it points to specifies a " "timeout for the wait. (This interval will be rounded up to the system clock " "granularity, and is guaranteed not to expire early.) The timeout is by " "default measured according to the B clock, but, since Linux " "4.5, the B clock can be selected by specifying " "B in I. If I is NULL, the call " "blocks indefinitely." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "I: for B, I is interpreted as a I " "value. This differs from other futex operations, where I is " "interpreted as an absolute value. To obtain the equivalent of B " "with an absolute timeout, employ B with I specified " "as B." msgstr "" # # #. FIXME . (Torvald) I think we should remove this. Or maybe adapt to a #. different example. #. For #. .BR futex (7), #. this call is executed if decrementing the count gave a negative value #. (indicating contention), #. and will sleep until another process or thread releases #. the futex and executes the #. .B FUTEX_WAKE #. operation. #. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "The arguments I and I are ignored." msgstr "" #. type: TP #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "B (since Linux 2.6.0)" msgstr "" #. Strictly speaking, since Linux 2.5.x #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "This operation wakes at most I of the waiters that are waiting (e.g., " "inside B) on the futex word at the address I. Most " "commonly, I is specified as either 1 (wake up a single waiter) or " "B (wake up all waiters). No guarantee is provided about which " "waiters are awoken (e.g., a waiter with a higher scheduling priority is not " "guaranteed to be awoken in preference to a waiter with a lower priority)." msgstr "" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "The arguments I, I, and I are ignored." msgstr "" #. type: TP #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "B (from Linux 2.6.0 up to and including Linux 2.6.25)" msgstr "" #. Strictly speaking, from Linux 2.5.x to Linux 2.6.25 #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "This operation creates a file descriptor that is associated with the futex " "at I. The caller must close the returned file descriptor after use. " "When another process or thread performs a B on the futex word, " "the file descriptor indicates as being readable with B