Pergunta

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?

Foi útil?

Solução

I assume the error is

mutex.cc: In function ‘int main()’:
mutex.cc:9: error: no matching function for call to ‘boost::condition_variable::wait(boost::unique_lock<boost::recursive_mutex>&)’
/opt/local/include/boost/thread/pthread/condition_variable.hpp:17: note: candidates are: void boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)
i

if not, please correct me. The documentation shows boost::condition_variable::lock takes a boost::unique_lock<boost::mutex> as an argument, not a boost::unique_lock<boost::recursive_mutex> as in your example.

Outras dicas

You should use condition_variable_any instead, the semantics of this version is the same, but it allows all kinds of lock types. The regular condition_variable is however said to be potentially faster.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top