简体   繁体   中英

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??

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM