By try_lock*
, I take to mean try_lock()
, try_lock_for()
, and try_lock_until()
. According to cppreference, all three methods may just fail spuriously. Following is quoted from the description for try_lock_for()
As with
try_lock()
, this function is allowed to fail spuriously and returnfalse
even if the mutex was not locked by any other thread at some point duringtimeout_duration
.
I know that spurious wakeup may happen with std::condition_variable
and the rationale behind it. But, what is the case with a mutex?
From C++14 chapter "30.4.1.2 Mutex types"
paragraph 16:
and paragraph 19:
And in answer to
std::timed_mutex
sometimes is implemented usingstd::condition_varible
when there is no direct support in the OS. As in GNU libstdc++:According to: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3209.htm