Is epoll thread-safe?

試著忘記壹切 提交于 2020-04-05 07:32:05

问题


There are two functions in epoll:

  1. epoll_ctl
  2. 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?


回答1:


It is thread-safe, but there isn't much documentation that explicitly states that - see http://linux.derkeiler.com/Mailing-Lists/Kernel/2006-03/msg00084.html

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 http://linux.die.net/man/2/epoll_ctl)



来源:https://stackoverflow.com/questions/7058737/is-epoll-thread-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!