Futex
Encyclopedia
A futex is a Linux
construct that can be used to implement basic locking, or as a building block for higher-level locking abstractions such as semaphore
s and POSIX
mutexes or condition variables.
A futex consists of a kernelspace
wait queue that is attached to an aligned
integer
in userspace. Multiple processes
or threads
operate on the integer entirely in user space (using atomic operations to avoid interfering with one another), and only resort to relatively expensive system call
s to request operations on the wait queue (for example to wake up waiting processes, or to put the current process on the wait queue). A properly programmed futex-based lock will not use system calls except when the lock is contended; since most operations do not require arbitration between processes, this will not happen in most cases.
Thomas J. Watson Research Center
), Matthew Kirkwood, Ingo Molnár
(Red Hat
) and Rusty Russell
(IBM Linux Technology Center). They first appeared in the development kernel version 2.5.7; the semantics stabilized as of version 2.5.40, and they are present in the 2.6.x stable kernel series.
In 2002, there were discussions to make futexes accessible via the file system, i.e. create a special node in /dev or /proc. However, Linus Torvalds
was heavily opposed to this idea and rejected any related patches.
Linux kernel
The Linux kernel is an operating system kernel used by the Linux family of Unix-like operating systems. It is one of the most prominent examples of free and open source software....
construct that can be used to implement basic locking, or as a building block for higher-level locking abstractions such as semaphore
Semaphore (programming)
In computer science, a semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access by multiple processes to a common resource in a parallel programming environment....
s and POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...
mutexes or condition variables.
A futex consists of a kernelspace
Kernel (computing)
In computing, the kernel is the main component of most computer operating systems; it is a bridge between applications and the actual data processing done at the hardware level. The kernel's responsibilities include managing the system's resources...
wait queue that is attached to an aligned
Data structure alignment
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. When a modern computer reads from or writes to a memory address, it will do this in word sized chunks...
integer
Integer
The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...
in userspace. Multiple processes
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...
or threads
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
operate on the integer entirely in user space (using atomic operations to avoid interfering with one another), and only resort to relatively expensive system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...
s to request operations on the wait queue (for example to wake up waiting processes, or to put the current process on the wait queue). A properly programmed futex-based lock will not use system calls except when the lock is contended; since most operations do not require arbitration between processes, this will not happen in most cases.
History
Futexes were created by Hubertus Franke (IBMIBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
Thomas J. Watson Research Center
Thomas J. Watson Research Center
The Thomas J. Watson Research Center is the headquarters for the IBM Research Division.The center is on three sites, with the main laboratory in Yorktown Heights, New York, 38 miles north of New York City, a building in Hawthorne, New York, and offices in Cambridge, Massachusetts.- Overview :The...
), Matthew Kirkwood, Ingo Molnár
Ingo Molnar
Ingo Molnár, currently employed by Red Hat, is a Hungarian Linux hacker. He is best known for his contributions to the operating system in terms of security and performance...
(Red Hat
Red Hat
Red Hat, Inc. is an S&P 500 company in the free and open source software sector, and a major Linux distribution vendor. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North Carolina with satellite offices worldwide....
) and Rusty Russell
Rusty Russell
Paul "Rusty" Russell is an Australian free software programmer and advocate.- Software development :Russell wrote the packet filtering systems ipchains and netfilter/iptables in the Linux operating system kernel...
(IBM Linux Technology Center). They first appeared in the development kernel version 2.5.7; the semantics stabilized as of version 2.5.40, and they are present in the 2.6.x stable kernel series.
In 2002, there were discussions to make futexes accessible via the file system, i.e. create a special node in /dev or /proc. However, Linus Torvalds
Linus Torvalds
Linus Benedict Torvalds is a Finnish software engineer and hacker, best known for having initiated the development of the open source Linux kernel. He later became the chief architect of the Linux kernel, and now acts as the project's coordinator...
was heavily opposed to this idea and rejected any related patches.
See also
- SynchronizationSynchronization (computer science)In computer science, synchronization refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, so as to reach an agreement or...
- Fetch-and-addFetch-and-addIn computer science, the fetch-and-add CPU instruction is a special instruction that atomically modifies the contents of a memory location. It is used to implement mutual exclusion and concurrent algorithms in multiprocessor systems, a generalization of semaphores.In uniprocessor systems, it is...
- Compare and swap
- Benaphores: the same principle was used on BeOS as early as 1996.