【发布时间】:2015-07-23 04:15:05
【问题描述】:
我正在处理条件变量,我假设它们在等待时解锁了相关的互斥锁。否则,互斥锁将永远不会被释放。但是,我在任何文档中都找不到此信息。考虑以下代码:
std::condition_variable consumerWakeMeUp;
std::mutex queueMutex;
// this locks the mutex
std::unique_lock<std::mutex> lk(queueMutex);
// going to sleep now
consumerWakeMeUp.wait(lk);
“consumerWakeMeUp.wait(lk)”是否解锁互斥锁?我必须假设否则线程将永远处理该互斥体。但如果有人知道更多细节,我将不胜感激。
谢谢。
【问题讨论】:
-
Yet, I can't find this information on any documentation实际上是第 1 点 here。
标签: c++ multithreading stl thread-safety