<s>
In	O
computing	O
,	O
a	O
futex	B-Application
(	O
short	O
for	O
"	O
fast	O
userspace	B-Operating_System
mutex	B-Operating_System
"	O
)	O
is	O
a	O
kernel	B-Operating_System
system	B-Operating_System
call	I-Operating_System
that	O
programmers	B-Application
can	O
use	O
to	O
implement	O
basic	O
locking	B-Operating_System
,	O
or	O
as	O
a	O
building	O
block	O
for	O
higher-level	O
locking	B-Operating_System
abstractions	O
such	O
as	O
semaphores	B-Operating_System
and	O
POSIX	O
mutexes	B-Operating_System
or	O
condition	O
variables	O
.	O
</s>
<s>
A	O
futex	B-Application
consists	O
of	O
a	O
kernel-space	B-Operating_System
wait	O
queue	O
that	O
is	O
attached	O
to	O
an	O
atomic	B-General_Concept
integer	O
in	O
userspace	B-Operating_System
.	O
</s>
<s>
Multiple	O
processes	B-Operating_System
or	O
threads	B-Operating_System
operate	O
on	O
the	O
integer	O
entirely	O
in	O
userspace	B-Operating_System
(	O
using	O
atomic	B-General_Concept
operations	I-General_Concept
to	O
avoid	O
interfering	O
with	O
one	O
another	O
)	O
,	O
and	O
only	O
resort	O
to	O
relatively	O
expensive	O
system	B-Operating_System
calls	I-Operating_System
to	O
request	O
operations	O
on	O
the	O
wait	O
queue	O
(	O
for	O
example	O
to	O
wake	O
up	O
waiting	O
processes	B-Operating_System
,	O
or	O
to	O
put	O
the	O
current	O
process	O
on	O
the	O
wait	O
queue	O
)	O
.	O
</s>
<s>
A	O
properly	O
programmed	O
futex-based	O
lock	B-Operating_System
will	O
not	O
use	O
system	B-Operating_System
calls	I-Operating_System
except	O
when	O
the	O
lock	B-Operating_System
has	O
contended	O
;	O
since	O
most	O
operations	O
do	O
not	O
require	O
arbitration	O
between	O
processes	B-Operating_System
,	O
this	O
will	O
not	O
happen	O
in	O
most	O
cases	O
.	O
</s>
<s>
On	O
Linux	B-Application
,	O
Hubertus	O
Franke	O
(	O
IBM	O
Thomas	O
J	O
.	O
Watson	O
Research	O
Center	O
)	O
,	O
Matthew	O
Kirkwood	O
,	O
Ingo	O
Molnár	O
(	O
Red	O
Hat	O
)	O
,	O
and	O
Rusty	O
Russell	O
(	O
IBM	O
Linux	B-Application
Technology	O
Center	O
)	O
originated	O
the	O
futex	B-Application
mechanism	O
.	O
</s>
<s>
Futexes	B-Application
appeared	O
for	O
the	O
first	O
time	O
in	O
version	O
2.5.7	O
of	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
development	O
series	O
;	O
the	O
semantics	O
stabilized	O
as	O
of	O
version	O
2.5.40	O
,	O
and	O
futexes	B-Application
have	O
been	O
part	O
of	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
mainline	O
since	O
the	O
December	O
2003	O
release	O
of	O
2.6.x	O
stable	O
kernel	B-Operating_System
series	O
.	O
</s>
<s>
In	O
2002	O
,	O
discussions	O
took	O
place	O
on	O
a	O
proposal	O
to	O
make	O
futexes	B-Application
accessible	O
via	O
the	O
file	O
system	O
by	O
creating	O
a	O
special	O
node	O
in	O
/dev	O
or	O
/proc	O
.	O
</s>
<s>
Futexes	B-Application
have	O
been	O
implemented	O
in	O
Microsoft	O
Windows	O
since	O
Windows	O
8	O
or	O
Windows	O
Server	O
2012	O
under	O
the	O
name	O
WaitOnAddress	O
.	O
</s>
<s>
In	O
2013	O
,	O
Microsoft	O
patented	O
futexes	B-Application
and	O
the	O
patent	O
was	O
granted	O
in	O
2014	O
.	O
</s>
<s>
In	O
May	O
2014	O
,	O
the	O
CVE	O
system	O
announced	O
a	O
vulnerability	O
discovered	O
in	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
's	O
futex	B-Application
subsystem	O
that	O
allowed	O
denial-of-service	O
attacks	O
or	O
local	O
privilege	O
escalation	O
.	O
</s>
<s>
In	O
May	O
2015	O
,	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
introduced	O
a	O
deadlock	O
bug	O
via	O
that	O
caused	O
a	O
hang	O
in	O
user	O
applications	O
.	O
</s>
<s>
The	O
bug	O
affected	O
many	O
enterprise	O
Linux	B-Application
distributions	O
,	O
including	O
3.x	O
and	O
4.x	O
kernels	B-Operating_System
,	O
and	O
Red	O
Hat	O
Enterprise	O
Linux	B-Application
version	O
5	O
,	O
6	O
and	O
7	O
,	O
SUSE	O
Linux	B-Application
12	O
and	O
Amazon	O
Linux	B-Application
.	O
</s>
<s>
Futexes	B-Application
have	O
been	O
implemented	O
in	O
OpenBSD	B-Operating_System
since	O
2016	O
.	O
</s>
<s>
The	O
futex	B-Application
mechanism	O
is	O
one	O
of	O
the	O
core	O
concepts	O
of	O
the	O
Zircon	O
kernel	B-Operating_System
in	O
Google	B-Application
's	I-Application
Fuchsia	B-Language
operating	I-Language
system	I-Language
since	O
at	O
least	O
April	O
2018	O
.	O
</s>
<s>
Futexes	B-Application
have	O
two	O
basic	O
operations	O
,	O
WAIT	O
and	O
WAKE	O
.	O
</s>
<s>
If	O
the	O
value	O
stored	O
at	O
the	O
address	O
addr	O
is	O
val	O
,	O
puts	O
the	O
current	O
thread	B-Operating_System
to	O
sleep	O
.	O
</s>
<s>
Wakes	O
up	O
num	O
number	O
of	O
threads	B-Operating_System
waiting	O
on	O
the	O
address	O
addr	O
.	O
</s>
<s>
If	O
the	O
value	O
stored	O
at	O
the	O
address	O
old_addr	O
is	O
val	O
,	O
wakes	O
num_wake	O
threads	B-Operating_System
waiting	O
on	O
the	O
address	O
old_addr	O
,	O
and	O
enqueues	O
num_move	O
threads	B-Operating_System
waiting	O
on	O
the	O
address	O
old_addr	O
to	O
now	O
wait	O
on	O
the	O
address	O
new_addr	O
.	O
</s>
<s>
This	O
can	O
be	O
used	O
to	O
avoid	O
the	O
thundering	B-Operating_System
herd	I-Operating_System
problem	I-Operating_System
on	O
wake	O
.	O
</s>
<s>
Then	O
it	O
will	O
wake	O
num1	O
threads	B-Operating_System
waiting	O
on	O
addr1	O
,	O
and	O
,	O
if	O
the	O
previously	O
read	O
value	O
from	O
addr2	O
matches	O
cmp_arg	O
using	O
comparison	O
cmp	O
,	O
will	O
wake	O
num2	O
threads	B-Operating_System
waiting	O
on	O
addr2	O
.	O
</s>
