为什么我必须有一个 boost::mutex for boost::condition_variable
why must I have a boost::mutex for boost::condition_variable?
我有以下代码:其中m_event是提升::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();
});
我真的不需要那个虚拟储物柜,我只是希望事件在某个布尔条件下停止,我不明白什么吗?
为什么我被迫使用假锁?
(附言代码效果很好。
编辑:事实上,如果我理解正确的话,我班上的是一个 boost::mutex,我们称之为m_mtx和明显的m_enqueue插入器。所以我正在根据锁更改我的实现以锁定m_lock然后机械臂只会做:
boost::mutex::scoped_lock<boost::mutex> guard(m_lock);
有意义?
timed_wait
等待获得锁,如果它及时这样做的话。
没有锁,它什么都做不了。
在我看来,你在滥用timed_wait
.
相关文章:
- 如何在 Linux for Windows 上通过 MinGW 构建静态 ICU 的 Boost
- Build Boost Regex for Windows VS2013
- Eclipse for C++ 无法识别酿造的 GSL 和 Boost 库
- building boost 1.64 for Visual Studio 2017
- Boost ASIO ForwardIterator for streambuf
- iostream GCC错误,转换为boost::filesystem::iostream for Windows
- Boost asio library for networking (http client)
- 无法在 Xcode 中使用 Boost,不断收到"Undefined symbols for architecture"错误
- BOOST :: simel_lock and Boost :: shared_lock for读者作者锁
- Boost Mutex implementation for Windows
- 为什么 read() 在管道连接到使用 boost::asio for STDIN/STDOUT 的程序时,使用 EAG
- boost::asio error for UDP async_receive
- std::lock() equivalent for boost::shared_mutex?
- 为什么我必须有一个 boost::mutex for boost::condition_variable
- Getter for boost::variant object
- G++ 无法使用 Boost for x86 编译代码
- Boost.Python - 不使用任何 boost for C++
- boost for android building boost log
- 使用Boost for Android在编译时引发错误
- OpenCV 2.4.5 和 Boost for Pass VideoCapture