std::this_thread和std::thread下的一些函数

1. std::thread

hardware_concurrency()静态函数

获取当前硬件支持多少个线程并行执行

get_id()

返回线程的id

2. std::this_thread

转载:中文标准库this_thread

this_thread是一个命名空间,不是类也不是头文件

get_id

获取当前进程id

yield

当前线程放弃执行,让操作系统调度另一线程继续执行

sleep_until

线程睡眠到指定的时刻

sleep_for

睡眠指定的时间

	using namespace std::chrono_literals;
	std::this_thread::sleep_for(5s);   //睡眠5s
	std::this_thread::sleep_for(100ms);//100ms
	std::this_thread::sleep_for(std::chrono::seconds(3));  //3s
	std::this_thread::sleep_for(std::chrono::milliseconds(1000));  //1000ms = 1s
posted @ 2021-05-20 17:27  滴哒哒哒  阅读(99)  评论(0编辑  收藏  举报