开发者

Executing epoll_ctl in one thread while the other thread is in the middle of epoll_wait

开发者 https://www.devze.com 2023-03-23 02:22 出处:网络
I am new to linux server programming with epoll. I have 2 threads: Thread_Accept and Thread_epoll. The former is block accept loop, if new connection is coming, it will add the new fd with epoll_ctl(

I am new to linux server programming with epoll. I have 2 threads: Thread_Accept and Thread_epoll. The former is block accept loop, if new connection is coming, it will add the new fd with epoll_ctl()开发者_如何学Go. The latter is a big epoll_wait() loop.

Now my question is: What if when Thread_Accept executing epoll_ctl() while the Thread_epoll is in the middle of epoll_wait? Will it got any side effect?

Thanks in advance.

regards, Martin


From the epoll_wait man page:

While one thread is blocked in a call to epoll_pwait(), 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.

So, no side effects when adding a new file descriptor :-)

(This man page note is the result of the bug mentioned by nathansizemore)


Why don't you make it one thread?

You can set the listener socket to nonblocking and add the socket to your big epoll_wait


From my experience, yes. But, this says otherwise

0

精彩评论

暂无评论...
验证码 换一张
取 消