Beispiel #1
0
int main(int argc, char **argv){

	bool ret = true;

	long size = sysconf(_SC_NPROCESSORS_ONLN);
	cout<<"number of workers: "<<size<<endl;

	ThreadPool p;

	ret = p.Init(size, start_routine, arg);
	if (!ret){
		return -1;
	}

	ret = p.Start();
	if (!ret){
		p.Shutdown();
		return -1;
	}

	int n = 3;
	while(n-->0){
		sleep(2);
	}
	p.Shutdown();

	return 0;
}
Beispiel #2
0
int main()
{
	ThreadPool* pTheadPool = ThreadPool::GetInstace();
	pTheadPool->Init(5);

	cout<<"main";
	for(int i=0; i<100; i++)
	{
		CTask* pTask = new CTask(i);
		pTheadPool->AddTask(pTask);
	}
	cout<<"Task added\n";	

	sleep(30);
	//可以设置线程池结束条件,需要结束的时候释放内存
	pTheadPool->Destory();
	delete pTheadPool;
	return 0;
}