So I have the following code, some of it left out so it's easier to understand.
for (unsigned int t = 0; t < NUM_THREADS; t++)
{
if (pthread_create(&threads[t], NULL, thread_run, (void*) &threadData) != 0)
{
perror("pthread_create");
}//end if
}
for (unsigned int z = 0; z < NUM_THREADS; z++)
{
if (pthread_join(threads[z], NULL) != 0)
{
perror("pthread_join");
}
}
My Problem is the join function, it is skipping the first thread I create, and co开发者_StackOverflow中文版ntinuing on. The current solution I have is adding an extra thread and not making the first one do any work.
Any ideas why this might be happening?
IMO there is not pthreads problem; you are just creating NUM_THREADS + 1
threads and join only first NUM_THREADS
of them.
精彩评论