networking · advanced · ~18 min · safe pentest lab
One-thread-per-connection pattern with pthread_detach.
Implement int serve_n_threads(int listening_fd, int n) that:
n clients sequentially.n accepts have been issued.Use pthread_detach so you don't have to join the threads explicitly.
The simplest concurrency model for a server: one thread per connection.
#include <pthread.h>
#include <sys/socket.h>
#include <unistd.h>
int serve_n_threads(int listening_fd, int n) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.