【发布时间】:2011-02-17 19:25:56
【问题描述】:
所以我有以下代码,其中一些省略了以便更容易理解。
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");
}
}
我的问题是连接函数,它跳过了我创建的第一个线程,然后继续。我目前的解决方案是添加一个额外的线程,而不是让第一个线程做任何工作。
任何想法为什么会发生这种情况?
【问题讨论】:
标签: multithreading join pthreads