3

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?

jotik
  • 17,044
  • 13
  • 58
  • 123
nicholas
  • 2,581
  • 14
  • 66
  • 104

2 Answers2

14

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.

jotik
  • 17,044
  • 13
  • 58
  • 123
Meros
  • 1,278
  • 11
  • 11
2

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.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87