1. 程式人生 > >c++11 執行緒池系列之一 所需要的join_threads

c++11 執行緒池系列之一 所需要的join_threads

class join_threads
{
std::vector<std::thread> &threads;
public:
	explicit join_threads(std::vector<std::thread> &threads_):threads(threads_){}
	~join_threads()
	{
	for(unsigned long i = 0 ; i < threads.size();++i)
	{
	if(threads[i].joinable())
		threads[i].join();
	}
	}
};