epoll是线程安全的吗?
epoll中有两个函数:
- epoll_ctl
- epoll_wait
当我使用相同的epoll_fd时,它们是线程安全吗?
如果一个线程调用epoll_wait,而其他线程同时调用epoll_ctl,会发生什么情况?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是线程安全的,但没有太多文档明确说明这一点。请参阅此处
顺便说一句,您还可以让多个线程在单个
epoll_fd
,但在这种情况下它可能会变得有点棘手。 (即,您可能想使用边缘触发EPOLLET
或一次性模式EPOLLONESHOT
。请参阅 此处。)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-triggeredEPOLLET
or oneshot modeEPOLLONESHOT
. See here.)是的,根据 手册页 用于
epoll_wait
。它明确允许在另一个线程中等待时将文件描述符添加到 epoll 集:“注释”部分:
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":