【问题标题】:C++ boost thread delayC++ 提升线程延迟
【发布时间】:2012-04-12 22:06:14
【问题描述】:

我想在 boost 线程中等待 1.5 秒。使用 boost::xtime 我可以等待整数秒:

// Block on the queue / wait for data for up two seconds.
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec++;
xt.sec++;
....
_condition.timed_wait(_mutex, xt)

如何改为等待 1.5 秒?

【问题讨论】:

    标签: c++ multithreading boost boost-thread


    【解决方案1】:

    使用纳秒和秒部分并增加 5 亿纳秒并增加一秒(即 1.5 秒),以下内容是否不起作用

    xt.sec++;
    xt.nsec += 500000000;
    _condition.timed_wait(_mutex, xt);
    

    【讨论】:

      猜你喜欢
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2017-07-20
      • 1970-01-01
      相关资源
      最近更新 更多