1、头文件
#include <iostream>
#include <thread> //线程
#include <string> //字符
using namespace;
2、创建线程
int main()
{
//创建线程
thread thread1(printHelloWorld,"aaaa");
//thread1.detach(); // 终端exe不显示结果,后台运行(一般配合多进程使用)
bool isJoin = thread1.joinable(); //判断是否可以使用join(严谨)
if(isJoin)
{
thread1.join(); //等子线程结束后再继续
}
return 0;
}
3、构建子线程执行的函数
void printHelloWorld(string msg)
{
cout<<msg<<endl;
return;
}