#include <iostream>
#include <thread>
int main(void)
{
std::thread x([]()->void {
int i = 4;
while (i--)
{
std::this_thread::sleep_for(std::chrono::seconds(2));
std::cout << "*" << std::endl;
}
return;
});
std::thread y([]()->void {
int i = 4;
while (i--)
{
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "-" << std::endl;
}
return;
});
std::cout << std::thread::hardware_concurrency() << std::endl; //检测计算机并发数
std::cout << "x.hand " << x.native_handle() << std::endl;
std::cout << "y.hand " << y.native_handle() << std::endl;
//脱离主线程后不能直接获取句柄,所以放输出语句后面后面
x.detach();
y.detach();
std::this_thread::sleep_for(std::chrono::seconds(30));//等待程序执行完成
return 0;
}