假设我通过调用创建 epoll 文件描述符 (epfd)
epfd = epoll_create( 10 );
接下来我通过调用 epoll_ctl(epfd,EPOLL_CTL_ADD,...) 将一些文件描述符添加到这个集合中,并通过在单独的线程中调用 epoll_wait 来等待事件循环中的事件。
如果我在 epoll 集不为空且 epoll_wait(epfd,...) 正在进行时关闭 epfd(通过在线程中调用 close(epfd),而不是 epoll_wait 线程)会发生什么? epoll_wait 终止了吗?有哪些结果?
最佳答案
可以预见的是,Linux 和 select(2)
做的事情是一样的。从手册页:
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)
.
从
select(2)
页面: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()
tl;博士;是“不要这样做”:
In summary, any application that relies on a particular behavior in this scenario must be considered buggy.
关于epoll - 当 epoll 文件描述符关闭时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26546858/