I am using a std::condition_variable
combined with a std::unique_lock
like this.
std::mutex a_mutex;
std::condition_variable a_condition_variable;
std::unique_lock<std::mutex> a_lock(a_mutex);
a_condition_variable.wait(a_lock, [this] {return something;});
//Do something
a_lock.unlock();
It works fine. As I understand, std::condition_variable
accepts a std::unique_lock
for it to wait. But, I am trying to combine it with std::lock_guard
but not able to.
My question is: Is it possible to replace std::unique_lock
with a std::lock_guard
instead ? This can relieve me from manually unlocking the lock every time I use it.
lock_guard
to work withcondition_variable_any
. The error message says something about missing member functionslock()
andunlock()
. Why is that? – Marpet