【发布时间】:2018-12-23 20:09:52
【问题描述】:
如何让两个线程互相等待,直到它们使用 pthread 完成一个循环?
void* th1Fn()
{
while(1)
{
//do something
printf("I'm done");
//signal that i'm done
//wait for thread2 so that I can repeat the cycle
}
}
void* th2Fn()
{
while(1)
{
//do something
printf("I'm done");
//signal that i'm done
//wait for thread1 so that I can repeat the cycle
}
}
【问题讨论】:
-
在线程之间来回悬挂信号量单元 - 很简单。不需要比这更复杂的了。
标签: c linux pthreads semaphore