I am creating a multithreaded server using epoll (edge-triggered) and non-blocking sockets. Currently I'm creating an event loop on the main thread and waiting for notifications and it works correctly
I have to choose between two approaches to make it multithreaded:
If I use the first method, is there a chance for multiple threads to get notified with the same event? how can I handle this situation?
What could be the best approach? Thank you.
I think option 1 is more popular since the primary purpose of non-blocking IO is to avoid the overhead of create & destroy threads.
take the popular web server nginx as an example, it create multiple processes (not threads) to handle incoming events on a handle, and the process the events in the subprocess. all of them share the same listening socket. it's quite similar to option 1.