Efficient multithreaded server P&L: -7 (≃ -540 CNY)
I have some epoll server code that I tweaked to run the server in a thread.
Now I'm taking this code and changing it so that each client connection is multiplexed by multiple threads.
一個問題是多線程的一個通用問題，它是從一個線程爲多種事件中的一種提供服務。我依賴於我正在輪詢 ringbuffer 和 epoll 的事實。
The idea is that each thread has a ringbuffer, when a socket is accepted, a message is put on the ringbuffer and the thread begins listening to that user.
All the other threads are notified of all the users so they can also echo data to them.
This is efficient as a thread can serve thousands-millions of connections and there are multiple threads.
One problem, which is a generic problem for multithreading is servicing one of multiple kinds of events from one thread. I rely on the fact I am polling a ringbuffer and epoll.