epoll 线程安全吗?

编程入门 行业动态 更新时间:2024-10-23 10:21:50
本文介绍了epoll 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

epoll中有两个函数:

There are two functions in epoll:

  • epoll_ctl
  • 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 线程安全吗?

    本文发布于:2023-11-25 18:55:56,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1630937.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:线程   epoll

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!