我浏览了 http://www.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html 中的文档但这没有明确提及。任何迅速的回应将不胜感激。
最佳答案
是的。这是常见的做法:
典型示例:
mutex queue_mutex;
cond queue_is_not_full_cond;
cond queue_is_not_empty_cond;
push()
lock(queue_mutex)
while(queue is full)
wait(queue_is_not_full_cond,queue_mutex);
do push...
signal(queue_is_not_empty_cond)
unlock(queue_mutex)
pop()
lock(queue_mutex)
while(queue is empty)
wait(queue_is_not_empty_cond,queue_mutex);
do pop...
signal(queue_is_not_full_cond)
unlock(queue_mutex)
关于c++ - 2 个 pthread 条件变量可以共享同一个互斥锁吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4062126/