boost:如何在给定的ptime之前使当前线程休眠?
boost: How to sleep current thread until given ptime?
不确定我是否遗漏了什么,但是如何将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();
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 在C++中使用cURL和多线程
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在cuda线程之间共享大量常量数据
- 如何将元素添加到数组的线程安全函数?
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 异常属于C++中的线程还是进程
- C++中的线程安全删除
- C++使用params创建线程函数会导致转换错误
- 类与私有变量的其他类之间的线程安全性
- CoInitialize()在单独的线程上崩溃而不返回
- c++中的线程池
- 线程之间的布尔停止信号
- 为什么std::async使用同一个线程运行函数
- 用于矢量处理的多个线程
- 如何获得当前线程的std ::线程
- 提升线程 检查当前线程是否等于另一个本机句柄