epoll 线程安全吗? [英] Is epoll thread-safe?

查看:53
本文介绍了epoll 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

epoll中有两个函数:

There are two functions in epoll:

  1. epoll_ctl
  2. epoll_wait

当我使用相同的 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 线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆