48 C++创建多个线程 和 等待多个线程

//C++创建多个线程 和 等待多个线程

class Teacher163 {
public:
	void teacher163threadfunc(int i) {
	}
};

void main() {
	vector vectorthreads;
	Teacher163 tea;

	//启动10个线程
	for (size_t i = 0; i < 10; i++)
	{
		vectorthreads.push_back(thread(&Teacher163::teacher163threadfunc, tea, i ));
	}
	//将这10个线程都join,等待多个线程join
	vector::iterator it;
	for (vector::iterator it = vectorthreads.begin(); it!=vectorthreads.end(); it++)
	{
		it->join();
	}
	cout << "duandian " << endl;
}

你可能感兴趣的:(c++)