【发布时间】:2012-02-07 06:55:31
【问题描述】:
在我的功能中的某一时刻,它会达到
pthread_cond_wait(&cond_state, &b_state);
当一个信号被发送并唤醒这个线程。它会在调用 Enter 之前立即尝试对互斥锁进行锁定吗?
void Enter(int g, int timer){
pthread_mutex_lock(&b_state);
if (room.state == 2 || room.state == g)
{
pthread_mutex_unlock(&b_state);
Leave();
}
else
{
pthread_cond_wait(&cond_state, &b_state);
Enter(g, timer); //Try to enter again
}
}
如果一个线程进入睡眠状态,我遇到一个问题,一旦它醒来,它会在调用 Enter 后卡在 mutex_lock。
【问题讨论】:
标签: pthreads mutex race-condition