0
在我的功能一個點,將達到Pthread的同步 - 調用pthread_cond_wait
調用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
}
}
我有一個問題,當如果一個線程睡覺去了,一旦它醒來,它會被卡在後調用的mutex_lock輸入。