下面代码已经说明问题
#include<thread>
#include<iostream>
using namespace std;
static const int numthread = 10;
void show(int i){
cout << "hello wolrd" <<i<< endl;
}
int main()
{
thread mythread[numthread];
for (int i = 0; i < numthread;i++)
{
mythread[i] = thread(show,i);
}
for (int i = 0; i < numthread; i++)
{
mythread[i].join();
}
return 0;
}
执行结果如下:
<img src="https://img-blog.csdn.net/20160719100040758?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />