Error forcing condition_variable

I see 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 for this error?

+3
source share
2 answers

I assume the error

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 what boost::condition_variable::locktakes boost::unique_lock<boost::mutex>as an argument, and not boost::unique_lock<boost::recursive_mutex>as in your example.

+2
source

Instead, you should use condition_variable_any, the semantics of this version are the same, but it allows you to use all types of locks. However, regular condition_variableis considered potentially faster.

+14
source

Source: https://habr.com/ru/post/1768753/


All Articles