MK.
MK.

Reputation: 34527

using std::condition_variable with std::timed_mutex

Is it possible? I want to use timed_mutex instead of a regular mutex with a condition_variable, but it won't compile and looking at sources

  void
  wait(unique_lock<mutex>& __lock, _Predicate __p)
  {
while (!__p())
  wait(__lock);
  }

(indentation courtesy of libc++ authors, really?)

So it looks like it is in fact limited to straight mutexes, not timed ones. But why??

Upvotes: 5

Views: 935

Answers (1)

Fran&#231;ois Andrieux
Fran&#231;ois Andrieux

Reputation: 29022

Yes, std::conditional_variable is limited to std::unique_lock<std::mutex>. However you can use the more generic std::condition_variable_any with anything that has a compatible interface.

Upvotes: 7

Related Questions