26.1 | In the fork example, there will be 101 descriptors in use, one listening socket, and 100 connected sockets. But each of the 101 processes (one parent, 100 children) has just one descriptor open (ignoring any others, such as standard input, if the server is not daemonized). In the threaded server, however, there are 101 descriptors in the single process. Each thread (including the main thread) is handling one descriptor. |
26.3 | This message should be printed by the main thread when it reads an EOF from the socket and the other thread is still running. A simple way to do this is to declare another external named done that is initialized to 0. Before the thread copyto returns, it sets this variable to 1. The main thread checks this variable, and if 0, prints the error message. Since only one thread sets the variable, there is no need for any synchronization. |