C++ boost 线程延迟

标签 c++ multithreading boost boost-thread

我想在 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 秒呢?

最佳答案

以下是否不能使用纳秒和秒部分并增加 5 亿纳秒并添加 1.5 秒的秒

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

关于C++ boost 线程延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10132566/

相关文章:

c++ - C++ 中的前向声明是什么?

c++/正在寻找有关目录和文件的文档(如 dirent.h)?

c++ - 单步执行直到退出没有行号信息的函数 __svfscanf_l

multithreading - 在 OS X 上,线程在后台 sleep 时间过长

c++ - 从char数组的元素中减去 'a'是什么意思

c++ - 为什么thread_local不能应用于非静态数据成员以及如何实现线程局部非静态数据成员?

c# - 异步循环不再有可用的 HttpContext

c++ - boost::bind、boost::asio、boost::thread 和类

c++ - 通过 boost append 到现有文件

c++ - 获取 boost message_queue 的名称