boost:如何在给定的ptime之前使当前线程休眠?

boost: How to sleep current thread until given ptime?

本文关键字:前线 线程 休眠 ptime boost      更新时间:2023-10-16

不确定我是否遗漏了什么,但是如何将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();
}

我正在使用提升版本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();