eventfd API Reference¶
Header¶
Prototype¶
Common Flags¶
| Flag | Purpose |
|---|---|
EFD_NONBLOCK |
Non-blocking eventfd |
EFD_CLOEXEC |
Close fd across exec() |
EFD_SEMAPHORE |
Semaphore-like read behavior |
Read / Write Format¶
uint64_t value = 1;
write(fd, &value, sizeof(value));
uint64_t count;
read(fd, &count, sizeof(count));
Both read and write must use 8 bytes.
Common Pitfalls¶
- eventfd is a counter, not a byte stream.
- Use
uint64_tfor read and write. - Read it after epoll reports readiness.
- Use a separate shared memory or queue if payload data is required.