最初我使用的是boost::mutex::scoped_lock
(有效)
boost::mutex::scoped_lock lock(mutex_name);
condition.wait(lock); //where condition = boost::condition_variable
但是后来我将锁更改为以下无法正常工作
boost::lock_guard<boost::mutex> lock(mutex_name)
condition.wait(lock); //Error
有关如何解决问题的任何建议我得到intellisense错误说明No instance of the overloaded function matches the argument list
。编译错误是
Error 7 error C2664: 'void boost::condition_variable::wait(boost::unique_lock<Mutex> &)' : cannot convert parameter 1 from 'boost::lock_guard<Mutex>' to 'boost::unique_lock<Mutex> &'
答案 0 :(得分:3)
boost::lock_guard
没有unlock
成员函数,这是condition
所需的。请改用unique_lock
:
boost::unique_lock<boost::mutex> lock(mut);
condition.wait(lock);