Originally Posted by
synthetix
I only need a filename variable from the producer thread, so I tried unlocking each thread after they acquire the filename. This works well, but once the loop in the producer is complete, the program quits before waiting for the rest of the threads to complete. This happens because those threads freed their locks very early, after they got their filenames. The real number crunching takes a little time so of course the producer thread quits immediately, terminating the worker threads while they're in the middle of crunching.
To deal with this, should I call pthread_join() for as many worker threads exist?
Here:
Code:
for(i=0;i<num_threads;i++){
pthread_join(threads[i],NULL);
}
return 0; //end of main
Actually, I just tried this, and it doesn't work since each thread is running an endless while() loop. Should I add a condition to the while()?