There are two functions in epoll:
- epoll_ctl
- epoll_wait
Are they thread-safe when I use the same epoll_fd?
What will happen if one thread calls epoll_wait and others call epoll_ctl at the same time?
There are two functions in epoll:
Are they thread-safe when I use the same epoll_fd?
What will happen if one thread calls epoll_wait and others call epoll_ctl at the same time?
Yes, it is thread-safe according to the manual page for epoll_wait
. It explicitly allows adding a file descriptor to an epoll set while it is being waited for in another thread:
Section "Notes":
While one thread is blocked in a call to epoll_wait(), it is possible for another thread to add a file descriptor to the waited-upon epoll instance. If the new file descriptor becomes ready, it will cause the epoll_wait() call to unblock.
© 2022 - 2025 — McMap. All rights reserved.