Is epoll thread-safe? Is epoll thread-safe? multithreading multithreading

Is epoll thread-safe?


It is thread-safe, but there isn't much documentation that explicitly states that. See here

BTW, you can also have multiple threads waiting on a single epoll_fd, but in that case it can get a bit tricky. (I.e. you might want to use edge-triggered EPOLLET or oneshot mode EPOLLONESHOT. See here.)


Note: The existing accepted answer is correct, but it mentions "there isn't much documentation that explicitly states that", while epoll documentation does state it.

The manual page for epoll_wait 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 possiblefor another thread to add a file descriptor to the waited-upon epollinstance. If the new file descriptor becomes ready, it will cause theepoll_wait() call to unblock.