C 11替代pthread_cond_timedwait

我需要让一个线程等到两个

>超时已过期,或
>变量由另一个线程更改

经过一些研究后我发现pthreads得到了pthread_cond_timedwait,如果我使用pthreads,这在这种情况下会很有用.

我正在使用C 11线程.没有完全传递给pthreads,有没有合适的替代方案?

解决方法

是的,你想要来自< condition_variable>的 std::condition_variable,它有一个需要一段时间的成员函数wait_for.

The condition_variable class is a synchronization primitive that can
be used to block a thread,or multiple threads at the same time,
until:

  • a notification is received from another thread
  • a timeout expires

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...