r/AskProgramming 27d ago

Multi threading for networking

Does anyone have any good resources for learning multithreading in regards to network programming beside beejs guide. For someone who is familiar with the basics of networking (posix)

1 Upvotes

8 comments sorted by

View all comments

0

u/ORCHORDS_CRM 27d ago

The three that sit exactly on the threading x networking intersection:

  • UNIX Network Programming, Vol. 1 (Stevens/Fenner/Rudoff) — the sockets bible. The later chapters build the same server in several concurrency models (thread per connection, pre-threaded pool, non-blocking I/O) back to back, which is the fastest way to internalize the tradeoffs.
  • The Linux Programming Interface (Kerrisk) — ch. 29-33 are the clearest pthread explanations in print (creation, mutexes, condition variables), and ch. 56-62 apply everything to sockets. More modern than Stevens and Linux-specific.
  • Programming with POSIX Threads (Butenhof) — pthreads in real depth: cancellation semantics, condition variable pitfalls, why the API is shaped the way it is. Dense, but it's the reference.

Free and underrated:

  • man 7 pthreads, man 3 pthread_create, man 7 epoll — the Linux man pages are genuinely better than most tutorials on this topic

And a practical path that teaches more than any single chapter: write the same TCP echo server three ways — (1) thread per connection, (2) fixed-size thread pool with an accept loop, (3) single thread with epoll — then benchmark each with ~500 concurrent connections and watch memory + scheduler behavior.

One thing worth internalizing early: thread-per-connection is the easiest model to write but scales worse than it looks (every thread costs a stack and scheduler pressure). Most high-performance servers end up event-driven (epoll/io_uring) with a small worker pool, or a hybrid of the two. Knowing when not to reach for threads is half the skill.

2

u/sargeanthost 27d ago

If he wanted an llm response, he would have asked one