使用 pthread_cond_t 我们必须关联一个互斥锁,当发出条件信号时,我看到了诸如
pthread_mutex_lock(&mutex);
//code that makes condition true
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
和
pthread_mutex_lock(&mutex);
//code that makes condition true
pthread_mutex_unlock(&mutex);
pthread_cond_broadcast(&cond);
哪一个是正确的方法?(有关系吗 ?)