本文介绍了为什么std :: condition_variable不能通过锁类型模板化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在调试模式下具有断言能力是非常有用的,因为开销相当小,互斥锁是否被锁定。查看已知选项,我选择了实现此选项由于低开销,使用 $
As can be seen, the method requires a very specific / p>
I don't understand
- 为什么会这样?
如果意图是强制使用 std :: unique_lock ,那么为什么不能使用以下内容:
Even if the intent was to enforce the use of std::unique_lock, then why couldn't the following be used:
template<class Predicate, class Lock=std::mutex> void wait(std::unique_lock<Lock> &lock, Predicate pred);
- li>
- how to reasonably get around this?
编辑
并进一步指出@TC,绝对正确和非常简单的解决方案是使用 <$
As explained by @Lingxi, and further pointed out by @T.C, the absolutely correct and very simple solution here is to use condition_variable_any, which was designed for stuff like this.
推荐答案
这篇关于为什么std :: condition_variable不能通过锁类型模板化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!