Home

eventfd

Eventfd is a Linux kernel synchronization primitive that provides a file descriptor-based event counter for signaling between processes or threads. It is commonly used to notify one execution context about events occurring in another without using heavier synchronization primitives, and it integrates with standard I/O multiplexing mechanisms such as poll, select, or epoll.

An eventfd object maintains a 64-bit unsigned counter. The constructor is int eventfd(unsigned int initval, int

Eventfd supports integration with I/O multiplexing. A thread or process can wait on the descriptor using poll,

Flags commonly used with eventfd include EFD_SEMAPHORE for semaphore-like behavior, EFD_NONBLOCK for non-blocking operations, and EFD_CLOEXEC

Common use cases include signaling the completion of work, waking an event loop, or implementing lightweight

flags)
(or
the
related
eventfd2
for
combined
flag
specification);
the
return
value
is
a
file
descriptor
referring
to
the
eventfd
object.
Writing
to
the
descriptor
adds
the
provided
64-bit
value
to
the
internal
counter.
Reading
retrieves
the
current
counter
value
and
resets
the
counter
to
zero;
if
the
EFD_SEMAPHORE
flag
is
set,
a
read
returns
1
and
decrements
the
counter
by
one,
enabling
semaphore-like
semantics.
If
the
counter
is
zero,
reads
block
unless
the
nonblocking
flag
(EFD_NONBLOCK)
is
set,
in
which
case
a
read
returns
the
error
EAGAIN.
select,
or
epoll,
and
a
producer
writing
to
the
descriptor
will
wake
waiters
once
the
counter
becomes
nonzero.
to
set
close-on-exec
semantics.
Eventfd2
provides
a
single
call
to
specify
these
flags
at
creation.
inter-thread
or
inter-process
notifications.
Eventfd
is
Linux-specific
and
is
not
a
part
of
the
POSIX
standard,
but
it
is
widely
available
on
modern
Linux
systems.