Home

eventfd2

Eventfd2 is a Linux kernel facility that provides a file descriptor for event notification between processes or threads. It is a variant of the eventfd mechanism that allows creation-time specification of flags, enabling different modes of operation and behavior without requiring subsequent fcntl calls.

The object created by eventfd2 represents a 64-bit unsigned counter. It is initialized to a user-specified value

Eventfd2 accepts creation flags that can be combined from among EFD_SEMAPHORE, EFD_NONBLOCK, and EFD_CLOEXEC. EFD_NONBLOCK makes

The descriptor is pollable and compatible with epoll, select, and similar mechanisms, making it suitable for

(initval).
Writing
to
the
descriptor
increments
the
counter
by
the
given
64-bit
value;
reading
retrieves
the
current
counter
value
and
typically
resets
the
counter
to
zero,
except
when
read
with
semaphore
semantics.
If
the
descriptor
is
created
with
the
EFD_SEMAPHORE
flag,
reads
decrement
the
counter
by
1
and
return
a
value
of
1,
providing
a
counting-semaphore
style
interface.
Without
EFD_SEMAPHORE,
a
read
returns
the
full
counter
value
and
clears
it
to
zero.
Writes
can
block
if
an
operation
would
overflow
the
64-bit
counter,
unless
the
descriptor
is
opened
with
EFD_NONBLOCK.
I/O
non-blocking
and
returns
EAGAIN
on
a
would-block
operation.
EFD_CLOEXEC
sets
the
close-on-exec
flag,
so
the
descriptor
is
automatically
closed
on
execve.
EFD_SEMAPHORE
changes
the
read
semantics
to
a
semaphore-like
behavior
as
described
above.
integrating
into
event
loops
or
signaling
workflows.
Typical
use
cases
include
signaling
completion
of
asynchronous
work,
waking
threads,
and
notifying
other
processes
without
shared
memory.
Eventfd2
is
Linux-specific
and
is
used
as
part
of
the
eventfd
family
for
lightweight,
race-free
inter-thread
or
inter-process
notifications.