16.3 Multithreaded Server
In this section, we’ll explore a simple example of multithreaded servers, which can handle multiple requests at any one time. For a refresher on multithreading, see Chapter 14.
The server code that we wrote in the previous section was based on a single thread, which is the main thread. The main thread is responsible for handling all incoming requests to server. A problem with a single threaded server is that it cannot handle multiple requests simultaneously. For example, if two requests arrive around the same time, the server will process the first request it receives and won’t handle the second one until it has finished processing the first. If, for any reason, the first request takes a while to process, the second ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access