You need to use EPOLLET
or EPOLLONESHOT
so that exactly one thread gets woken by the EPOLLIN
event when a new connection comes in. The handling thread then needs to call accept
in a loop until it returns EAGAIN
(EPOLLET
) or manually reset with epoll_ctl
(EPOLLONESHOT
) in order for more connections to be handled.
In general when using multiple threads and epoll, you want to use EPOLLET
or EPOLLONESHOT
. Otherwise when an event happens, multiple threads will be woken to handle it and they may interfere with each other. At best, they'll just waste time figuring out that some other thread is handling the event before waiting again. At worst they'll deadlock or corrupt stuff.