Is epoll thread-safe?

前端 未结 2 2016
梦如初夏
梦如初夏 2020-12-23 17:04

There are two functions in epoll:

  1. epoll_ctl
  2. epoll_wait

Are they thread-safe when I use the same epoll_fd?
What wi

2条回答
  •  孤独总比滥情好
    2020-12-23 17:34

    Note: The existing accepted answer is correct, but it mentions "there isn't much documentation that explicitly states that", while epoll documentation does state it.

    The manual page for epoll_wait explicitly allows adding a file descriptor to an epoll set while it is being waited for in another thread:

    Section "Notes":

    While one thread is blocked in a call to epoll_wait(), it is possible for another thread to add a file descriptor to the waited-upon epoll instance. If the new file descriptor becomes ready, it will cause the epoll_wait() call to unblock.

提交回复
热议问题