#include<iostream>
#include<thread>
#include<string>
using namespace std;
void printString(string str) {
cout << str<<endl;
return;
}
int main() {
//1、创建线程 thread 线程名(函数名,参数1,...,参数N);
thread thread1(printString, "51522");
thread thread2(printString, "114514");
thread thread3(printString, "1919810");
thread1.join();//等待线程完成
thread2.detach();//线程在后台完成,分离线程
bool isJoin=thread3.joinable();//判断线程能否完成执行,是返回1,否返回0
if (isJoin) {
thread3.join();
}
return 0;
}
C++多线程之创建线程及运行
最新推荐文章于 2024-10-16 10:13:45 发布