头文件:<thread>                  (C++11)

template<class Clock, class Duration>

void sleep_until(const std::chrono::time_point<Clock, Duration>& sleep_time);

作用:

阻塞当前正在执行的线程直到sleep_time溢出。

sleep_time是和时钟相关联的,也就是要注意时钟调整会影响到sleep_time。因此,

时钟的时长有可能或没有可能会短于或长于sleep_time。Clock::now()返回调用这个函数时的时间,取决于调整方向。该函数也有可能因为调度或者资源竞争而导致阻塞时间延长到sleep_time溢出之后。

参数:

sleep_time 阻塞时长

返回值:

none

异常:

任何从Clock或Duration抛出的异常(由标准库提供的时钟和时长从来都不会抛出异常)

实例:

 #include <iostream>
#include <iomanip>
#include <chrono>
#include <ctime>
#include <thread>
#pragma warning(disable:4996)//加上可去掉unsafe 请使用localtime_s的编译报错
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'; //必须大写X,若小写x,输出的为日期
std::cout << "Waiting for the next minute to begin...\n";
++ptm->tm_min;
ptm->tm_sec = ;
std::this_thread::sleep_until(system_clock::from_time_t(mktime(ptm)));
std::cout << std::put_time(ptm, "%X") << "reached!\n";
getchar();
return ;
}

结果:

std::this_thread::sleep_until的更多相关文章

  1. std::this_thread::yield/sleep_for

    std::this_thread::yield(): 当前线程放弃执行,操作系统调度另一线程继续执行.. std::this_thread::sleep_for(): 表示当前线程休眠一段时间,休眠期 ...

  2. android ndk下没有pthread_yield,好在std::this_thread::yield()可以达到同样的效果

    一个多线程的算法中,发现线程利用率只有47%左右,大量的处理时间因为usleep(500)而导致线程睡眠: 性能始终上不去. 把usleep(500)修改为std::this_thread::yiel ...

  3. c++多线程基础2(命名空间 this_thread)

    整理自:zh.cppreference.com/w/cpp/thread std::this_thread::yield: 定义于头文件 <thread> 函数原型:void yield( ...

  4. 第24课 std::thread线程类及传参问题

    一. std::thread类 (一)thread类摘要及分析 class thread { // class for observing and managing threads public: c ...

  5. [原]C++新标准之std::chrono::time_point

    原 总结 STL 标准库 chrono time_point ratio  概览 类定义 总结 思考 拓展 system_clock steady_clock high_resolution_cloc ...

  6. [原]C++新标准之std::chrono::duration

    原 总结 C++11 chrono duration ratio  概览 std::chrono::duration 描述 类定义 duration_cast()分析 预定义的duration 示例代 ...

  7. Game Engine Architecture 3

    [Game Engine Architecture 3] 1.Computing performance—typically measured in millions of instructions  ...

  8. C++时间

    C++时间 头文件 chrono, 命名空间 std. 现在时间 std::chrono::system_clock::now() 返回系统时钟的当前时间 时钟 std::chrono::system ...

  9. C/C++ Sleep(0)

    Sleep(0) 的意义是放弃当前线程执行的时间片,把自身放到等待队列之中.这时其它的线程就会得到时间片进行程序的程序.Sleep(0)能够降低当前线程的执行速 度,比如:现在系统中有100个线程(先 ...

随机推荐

  1. ajax提交表单包含文件

    需要用到  FormData. html: <form id="formPost"> name: <input name="name" /&g ...

  2. 用ufile和S3代替hdfs存储数据

    一,添加ufile需在配置中添加: core-site.xml添加如下配置:<property><name>fs.ufile.impl</name><valu ...

  3. 自然语言处理工具HanLP-N最短路径分词

    本篇给大家分享baiziyu 写的HanLP 中的N-最短路径分词.以为下分享的原文,部分地方有稍作修改,内容仅供大家学习交流! 首先说明在HanLP对外提供的接口中没有使用N-最短路径分词器的,作者 ...

  4. 如何重装mysql8及初次修改密码

    首先在设置里卸载旧版的mysql 然后把你之前的安装的mysql文件夹整个删掉 然后删除注册表的MySQL信息 安装新版的MySQL 新建并配置my-default.ini文件 如下: [mysqld ...

  5. ABC133F Small Products

    考虑 DP. 状态 令 $f[\ell][x]$ 表示长度为 $\ell$,首项不超过 $x$ 的序列的个数. 答案是 $f[K][N]$. 有递推 $f[\ell][x] = f[\ell][x - ...

  6. python-day38(正式学习)

    目录 线程 线程开启的两种方式 1 2 子线程和子进程的创建速度 子线程共享资源 线程的join方法 守护线程 线程其他用法 线程 线程开启的两种方式 1 from threading import ...

  7. python-day31(正式学习)

    一.单机架构 应用领域: 植物大战僵尸 office 二.CS架构 应用领域: QQ 大型网络游戏 计算机发展初期用户去取数据,直接就去主机拿,从这里开始就分出了客户端和服务端. 客户端:用户安装的软 ...

  8. python之函数、面向对象

    学习python到了函数这一块进度有所放缓,主要还是想理解透彻,毕竟直觉告诉我函数是python是其中的关键,不管是模块.还是包.或者是库,都是建立在若干个函数定义上面. 章节后面就是关于面向对象编程 ...

  9. 用data的方法获取值的时候,要注意的问题一定要在先封装好

    var art=$(".add-more").prev().find(".content").data("list1"); 我们一定要在aj ...

  10. Max History CodeForces - 938E (组合计数)

    You are given an array a of length n. We define fa the following way: Initially fa = 0, M = 1; for e ...