本文介绍了epoll 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
epoll_ctl epoll_wait
epoll中有两个函数:
There are two functions in epoll:
当我使用相同的 epoll_fd 时,它们是否线程安全?如果一个线程调用epoll_wait,其他线程同时调用epoll_ctl,会发生什么?
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?
推荐答案它是线程安全的,但没有太多文档明确说明这一点.请参阅此处
It is thread-safe, but there isn't much documentation that explicitly states that. See here
顺便说一句,您也可以让多个线程在单个 epoll_fd 上等待,但在这种情况下会有点棘手.(例如,您可能想使用边缘触发的 EPOLLET 或 oneshot 模式 EPOLLONESHOT.请参阅 这里.)
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.)
更多推荐
epoll 线程安全吗?
发布评论