C++11 this_thread::sleep_until(11)

原文地址:http://www.cplusplus.com/reference/thread/this_thread/sleep_until/
function
<thread>

std::this_thread::sleep_until

template <class Clock, class Duration>
  void sleep_until (const chrono::time_point<Clock,Duration>& abs_time);
Sleep until time point
Blocks the calling thread until abs_time.

阻塞当前线程直到abs_time时间点到来。


The execution of the current thread is stopped until at least abs_time, while other threads may continue to advance.
该线程阻塞至少直到时间点abs_time到来。其他线程可能提前。

Parameters

abs_time
A point in time when the calling thread shall resume its execution.
Note that multi-threading management operations may cause certain delays beyond this.

time_point is an object that represents a specific absolute time.

线程应该恢复执行的时间点。


Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// this_thread::sleep_for example
#include <iostream>       // std::cout
#include <iomanip>        // std::put_time
#include <thread>         // std::this_thread::sleep_until
#include <chrono>         // std::chrono::system_clock
#include <ctime>          // std::time_t, std::tm, std::localtime, std::mktime

int main() 
{
  using std::chrono::system_clock;
  std::time_t tt = system_clock::to_time_t (system_clock::now());

  struct std::tm * ptm = std::localtime(&tt);
  std::cout << "Current time: " << std::put_time(ptm,"%X") << '\n';

  std::cout << "Waiting for the next minute to begin...\n";
  ++ptm->tm_min; ptm->tm_sec=0;
  std::this_thread::sleep_until (system_clock::from_time_t (mktime(ptm)));

  std::cout << std::put_time(ptm,"%X") << " reached!\n";

  return 0;
}


Output (after an avg. of 30 seconds):
Current time: 11:52:36
Waiting for the next minute to begin...
11:53:00 reached!

Exception safety

If the type of abs_time never throws exceptions (like if it only uses values from the standard clocks provided in header <chrono>), this function never throws exceptions (no-throw guarantee).


—————————————————————————————————————————————————————————————————

//写的错误或者不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

转载请注明出处:http://blog.csdn.net/qq844352155

author:天下无双

Email:coderguang@gmail.com

2014-9-4

于GDUT

——————————————————————————————————————————————————————————————————






  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值