#include <iostream>
#include <thread>
#include <functional>
using namespace std;
void test()
{
cout << "线程已启动" << endl;
int i = 90;
while(--i > 0)
{
cout << i << endl;
}
cout << "线程结束" << endl;
}
int main()
{
thread *t1 = new thread(test);
int i = 900000;
while(--i > 0) ;
return 0;
}
thread th_;
th_ = thread(test);
int i = 900000;
while(--i > 0) ;
本来就是如此啊
join只是阻塞当前线程,直到线程结束
如果创建一个线程不做处理会调用abort函数终止程序
test1.detach();//这样的话主线程直接结束,不能在终端显示
test1.join();//阻塞,等待子线程结束,才会进行主进程