【发布时间】:2014-10-02 20:52:27
【问题描述】:
对于以下代码:
f1()
{
pthread_mutex_lock(&mutex); //LINE1 (thread3 and thread4)
pthread_cond_wait(&cond, &mutex); //LINE2 (thread1 and thread2)
pthread_mutex_unlock(&mutex);
}
f2()
{
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond); //LINE3 (thread5)
pthread_mutex_unlock(&mutex);
}
假设 thread1 和 thread2 在 LINE2 等待,thread3 和 thread4 在 LINE1 被阻塞。当thread5执行LINE3时,哪些线程会先运行?线程1还是线程2?线程3还是线程4?
【问题讨论】:
标签: pthreads