Thread Per-Request (Cont.) Now the request handling function. void* handle_request(void* data) { struct handler_thread_data* pdata = (struct handler_thread_data*)data; /* must be detached, since we don't use 'join' */ /* to synchronize our termination. */ pthread_detach(pthread_self()); handle_request(pdata->request); free_request_data(pdata->request); /* notify 'management' that we're done. */ pthread_mutex_lock(&pdata->threads->mutex); pdata->threads->num_threads--; pthread_cond_signal(&pdata->threads->cond); pthread_mutex_unlock(&pdata->threads->mutex); free(pdata); /* no one else can free this. */ return NULL; }