Implementing A Thread Pool (Cont.) generate_requests(); wait_for_no_new_requests(); /* notify all threads they should terminate. */ pthread_mutex_lock(*(q->mutex)); pool_exit = 1; pthread_cond_broadcast(*(q->cond)); pthread_mutex_unlock(*(q->mutex)); /* wait for all thread to terminate. */ for (i=0; i<10; i++) { void* thr_retval; /* ignored anyway. */ pthread_join(&threads[i], &thr_retval); } return 0; }