문제

Can you combine std::recursive_mutex with std::condition_variable, meaning do something like this:

std::unique_lock<std::recursive_mutex> lock(some_recursive_mutex)
some_condition_var.wait(lock);

If it's not allowed, then why not?

I am using VC++11.

도움이 되었습니까?

해결책

You can, if you use std::condition_variable_any, which allows for any type of object that supports the Lockable concept.

However, in the case of recursive mutex, you do have to ensure that the given thread has only locked the recursive mutex once, since the condition variable only will use the unlock method on the unique_lock once during the wait.

다른 팁

You can do that with a std::condition_variable_any which can take any kind of lockable but plain std::condition_variable is specialized for std::unique_lock<std::mutex>.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top