while(pass == 0)
pthread_cond_wait(...);
pass = 1;pthread_cond_signal(...)
// 条件测试
pthread_mutex_lock(mtx);while(pass == 0)
pthread_cond_wait(...);pthread_mutex_unlock(mtx);
// 条件发生修改,对应的signal代码pthread_mutex_lock(mtx);pass = 1;pthread_mutex_unlock(mtx);pthread_cond_signal(...);
// 条件测试
pthread_mutex_lock(mtx);while(pass == 0) {
pthread_mutex_unlock(mtx);
pthread_cond_just_wait(cv);
pthread_mutex_lock(mtx);}pthread_mutex_unlock(mtx);
// 条件发生修改,对应的signal代码pthread_mutex_lock(mtx);pass = 1;pthread_mutex_unlock(mtx);pthread_cond_signal(cv);
为什么pthread_cond_wait需要传递mutex参数,布布扣,bubuko.com
为什么pthread_cond_wait需要传递mutex参数
原文地址:http://blog.csdn.net/booirror/article/details/30395111