Suppose I create epoll file descriptor (epfd) by call
epfd = epoll_create( 10 );
Next I adding some count of file descriptors into this set by calling epoll_ctl(epfd,EPOLL_CTL_ADD,...) and wait for events in event loop by calling epoll_wait in separate thread.
What happened if I close epfd (by call close(epfd) in thread, other then epoll_wait thread) when epoll set is not empty and epoll_wait(epfd,...) in progress? Is epoll_wait terminated? With which results?
Predictably, Linux does the same thing as it does for select(2)
. From the manual page:
For a discussion of what may happen if a file descriptor in an epoll instance being monitored by
epoll_wait()
is closed in another thread, seeselect(2)
.
And from the select(2)
page:
If a file descriptor being monitored by
select()
is closed in another thread, the result is unspecified. [...] On Linux (and some other systems), closing the file descriptor in another thread has no effect onselect()
The tl;dr; is "don't do it":
In summary, any application that relies on a particular behavior in this scenario must be considered buggy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With