I have a design consideration to make using multi threading (pthreads) to handle multiple client connections over tcp. On Linux. Keeping in mind that I am writing a (dynamic) thread pool.
That said, I came up with two different designs:
1. Employ some kind of queue structure/ linked list of connected clients and let the workers take them of the queue, mutex lock taking care of race conditions. The main thread will fill the queue with accepted connections.
or
2. Main thread will bind a socket and the workers will accept the client connections.c (the worker threads get a handle to the socket and just listen)
If my understanding is correct, the OS will decide handle which worker gets the connection
Which of these would be preferable/ best performing? Any suggestions or other possibly better solutions are welcome! I am here to learn