I have a std::condition_variable_any
that waits on a custom lock which is a composition of two mutexes (one std::mutex
and one shared-locked std::shared_mutex
). Its unlock()
operation simply unlocks both mutexes sequentially.
For example (pseudocode):
mutex mutex1;
shared_mutex mutex2;
condition_variable_any cv;
// acquiring the locks
DualLock lock(unique_lock(mutex1), shared_lock(mutex2));
// waiting
cv.wait(lock);
cv.wait()
should atomically unlock both mutex1
and mutex2
, and put the thread to sleep until cv
gets notified.
It it still guaranteed that the thread is sleeping and listening to the condition variable notification, once any of mutex1
or mutex2
is unlocked?
Or is it possible that one mutex gets unlocked, and a second thread locks it, sends the notification, but this first thread was not yet sleeping and listening. So the notification never arrived and no wakeup occurs.