About Building a Multithreaded Web Server

In the last chapter, I'm a bit suspicious about the output of the console. Why is the request output Shutting down after the first request. Then the program can request a second time, and the output Shutting down means that the listener is no longer processing requests.
Development environment:Chrome 113.0.5672.126 (arm64);Apple M2
output is:
Shutting down.
Worker 0 got a job; executing.
Worker 1 disconnected; shutting down.
Worker 2 got a job; executing.
Worker 3 disconnected; shutting down.
Shutting down worker 0
Worker 0 disconnected; shutting down.
Shutting down worker 1
Shutting down worker 2

Worker 2 disconnected; shutting down.
Shutting down worker 3

for stream in listener.incoming().take(2) {

Listener accepts steams. When it stops the streams still exist if code for them hasn't finished.
The output lines "Shutting down.", "Worker X got a job; executing." are from different threads and nothing stops the CPU from processing one output before the other.

Thanks for replying, then the first web page request threads 0 and 1 are executed because of tcp's SYN and ACK?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.