c++11 批量產生多個線程

下面代碼已經說明問題


#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="" />


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章