Boost条件变量参数错误
我在下面的代码中遇到错误。
recursive_mutex m_RecurMutex;
condition_variable cond;
unique_lock<recursive_mutex> lock(m_RecurMutex);
cond.wait(lock); // Error Here.
造成这个错误的原因是什么?
I encounter an error in the code below.
recursive_mutex m_RecurMutex;
condition_variable cond;
unique_lock<recursive_mutex> lock(m_RecurMutex);
cond.wait(lock); // Error Here.
What is the reason causing this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
condition_variable_any
来代替,这个版本的语义是相同的,但它允许各种锁类型。不过,据说常规的condition_variable
可能会更快。You should use
condition_variable_any
instead, the semantics of this version is the same, but it allows all kinds of lock types. The regularcondition_variable
is however said to be potentially faster.我认为错误是
,如果不是,请纠正我。 文档 显示
boost::condition_variable::lock
采用boost::unique_lock
作为参数,而不是boost::unique_lock
如您的示例所示。I assume the error is
if not, please correct me. The documentation shows
boost::condition_variable::lock
takes aboost::unique_lock<boost::mutex>
as an argument, not aboost::unique_lock<boost::recursive_mutex>
as in your example.