At one point in my function it would reach
pthread_cond_wait(&cond_state, &b_state);
When a signal is send and wake up this thread. Does it immediately try to do a lock on mutex before it calls 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
}
}
I am having a problem when if a thread went to sleep, once it woke up it will get stuck at mutex_lock after called Enter.
Yes, the manpage for
pthread_cond_waitsays: