Is it possible to add a socket to an epoll descriptor while another thread is waiting for that epoll descriptor?
I have multiple threads, one of them calls epoll_wait
in a loop, the others can open connections that should be epoll
'ed on the first thread. Is it possible to just add new sockets using epoll_ctl
while another thread is waiting in epoll_wait
?
What happens in the following scenario:
- Topic 1 calls epoll_wait.
- Thread 2 creates socket (A) and adds it to the epoll instance using epoll_ctl.
- Someone sends some data, socket A becomes ready to call read ().
Will epoll_wait return socket A?
source to share
Yes, it will. The whole point of socket epoll
is that you don't have to duplicate effort. Snapshot or multiple wait queues are not involved.
Under the hood, the epoll socket has a waiting queue. When you block an epoll socket, you are added to this single wait queue. The state doesn't persist or something. The state is in the eplom-cell itself.
source to share