Use a condition variable which in pthreads is pthread_cond_t
. Have the main thread wait on the condition variable, and right before a thread dies have it signal the condition variable. In pseudo code something like this:
main thread
//spawn first set of threads
while(!done) {
pthread_cond_wait(&cond, &mutex);
//spawn another thread
}
worker thread
//traverse maze
pthread_cond_broadcast(&cond);
//thread exit
Note that when using a condition variable you need to acquire and release an associated mutex. Look at the man page for pthread_cond_wait
for more details.