问题
There are two functions in epoll:
- epoll_ctl
- 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