I understand the basics of POSIX networking and sockets, but I want to build a stronger foundation in multithreading as it applies to network programming. I've used threads, locks, and related concepts before, but they still don't fully click for me. I'm looking for books, documentation, tutorials, or practical exercises beyond Beej's Guide that explain the tradeoffs between different server designs, such as one thread per connection, thread pools, and event-driven approaches like epoll.
3 Answers
A good set of references is UNIX Network Programming, Volume 1, The Linux Programming Interface, and Programming with POSIX Threads. The first compares several concurrent server designs, including thread-per-connection and pre-threaded servers. The Linux Programming Interface gives a clear treatment of pthreads, mutexes, condition variables, and sockets, while Butenhof’s book goes deeper into pthread behavior and common pitfalls. The Linux man pages for pthreads, pthread_create, and epoll are also worth reading directly.
Before focusing specifically on networking, make sure threads, synchronization, and condition variables are solid on their own. Networking mainly adds blocking I/O, connection management, and scaling concerns. Also, don’t assume that one thread per socket is the standard solution—thread creation and stack memory become expensive at scale, which is why many high-performance servers use epoll or io_uring with a small worker pool.
The most useful way to learn this is to build the same TCP echo server several times: first with one thread per connection, then with a fixed-size worker pool, and finally with a single event loop using epoll. Test them with hundreds of simultaneous connections and compare memory use, latency, and scheduler overhead. That makes the tradeoffs much easier to understand than reading about them in isolation.

I’ve used threads and locks before, but I’m going back through the fundamentals so I can understand the design choices rather than just copy a pattern.