#include <iostream>
#include <thread>
using namespace std;
void threadPrint(int threadIndex)
{
for (int i = 0; i < 4; i++)
{
cout << "hello other<"<<threadIndex<<"> thread "<< endl;
}
}
void mainPrint()
{
for (int i = 0; i < 4; i++)
{
cout << "hello main thread" << endl;
}
}
int main()
{
//定义线程数组
thread threadPrintArray[3];
for (int i = 0; i < 3; i++)
{
threadPrintArray[i]=thread(threadPrint, i*100);
}
//使用线程
for (int i = 0; i < 3; i++)
{
threadPrintArray[i].detach();
}
mainPrint();
getchar();
return 0;
}
Server - 线程数组
于 2019-08-07 20:13:07 首次发布