epoll - 当 epoll 文件描述符关闭时会发生什么?

标签 epoll

假设我通过调用创建 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, see select(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 on select()



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/

相关文章:

c - 为什么EPOLLOUT没有被触发?

c++ - libevent 的附加值

python - 与 epoll 的 kqueue 注销函数类似的函数是什么?

c++ - 当 epoll 发出事件信号时,recv() 调用如何阻塞?

c - epoll 读取错误的字节

c++ - 使用 epoll 处理多个并发请求

c++ - boost Asio 单线程性能

c++ - 子进程能够更改父进程的 epoll 状态

c - 边缘触发的非阻塞 epoll 的 SSL_accept 总是返回 SSL_ERROR_WANT_READ

c - Linux epoll如何检查就绪fd : Sync or Async?