【发布时间】:2014-01-12 18:14:20
【问题描述】:
我有以下代码: 其中 m_event 是一个 boost::condition_variable
boost::scoped_lock dummy;
boost::unique_lock<boost::scoped_lock> lock(dummy); // TODO: see if dummy is correct
m_event.wait(lock, [this] () {
return !this ->m_enqueue.empty();
});
我真的不需要那个虚拟储物柜我只是希望事件在某个布尔条件下停止, 我有什么不明白的吗?
为什么我不得不使用假锁?
(P.S. 代码效果很好..)
编辑: 事实上,如果我理解正确的话,我在课堂上拥有的是 boost::mutex,我们称之为 m_mtx 和明显的插入器到 m_enqueue.. 所以我将我的实现相应地更改为锁定 m_lock ,然后插入器只会这样做:
boost::mutex::scoped_lock<boost::mutex> guard(m_lock);
有意义吗?
【问题讨论】:
-
@ichramm:这是个问题!还有it's a subtly different one,在那...
标签: c++ boost boost-asio mutex