c++ - boost:如何使当前线程休眠直到给定 ptime?

标签 c++ boost

不确定我是否遗漏了什么,但我怎么能通过 boost::posix_time::ptime反对 boost::this_thread::sleep_until() ?更具体地说:我如何从 boost::posix_time::ptime 转换至 boost::chrono::time_point ?

void do_magic( const boost::posix_time::ptime& wakeup_time )
{
    boost::this_thread::sleep_until( wakeup_time ); // not working

    do_more_magic();
}

我正在使用 boost 版 1.62 ,如果这有任何相关性。

最佳答案

同时,此问题已通过 deadline_timer 解决。 . boost::asio 有解决方法:

// Construct a timer without setting an expiry time.
boost::asio::deadline_timer timer(my_context);

// Set an expiry time relative to now.
timer.expires_from_now(boost::posix_time::seconds(5));

// Wait for the timer to expire.
timer.wait();

关于c++ - boost:如何使当前线程休眠直到给定 ptime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59280774/

相关文章:

c++ - 使 Boost.Spirit 解析器跳过所有空格

c++ - 如何使用 boost.Qi 解析此类 XML 并调用名为标签的函数?

C++ std::locale ("en") 在 iOS 上抛出异常

c++ - 如何在 boost::statechart state_machine 对象中获取当前最派生的状态?

c++ - 通过 boost::random 在 C++ 中随机生成 128 位(uint128_t)

c++ - 尝试获取不存在的节点时如何不出现任何错误

c++ - 在cygwin上编译Boost asio出现很多错误

c++ - '...' 标记调用模板类的模板化方法之前的预期主表达式

c++ - 如何设置 float* 参数的默认值,它应该是指向数组的指针

c++ - 如何使用 Boost XML 解析器