6 #ifdef GRT_CXX11_ENABLED
8 std::atomic< unsigned int > ThreadPool::threadPoolSize( std::thread::hardware_concurrency() );
13 #ifdef GRT_CXX11_ENABLED
15 launchThreads( threadPoolSize );
21 #ifdef GRT_CXX11_ENABLED
23 launchThreads( poolSize );
30 std::cout <<
"~ThreadPool()\n";
31 #ifdef GRT_CXX11_ENABLED
33 condition.notify_all();
34 for(std::thread &worker: workers)
39 #ifdef GRT_CXX11_ENABLED
40 void ThreadPool::launchThreads(
const unsigned int poolSize ){
43 for(
unsigned int i = 0; i<poolSize; ++i)
49 std::function< void() > task;
53 std::unique_lock<std::mutex> lock(this->queue_mutex);
54 this->condition.wait(lock,
55 [this]{ return this->stop || !this->tasks.empty(); });
56 if(this->stop && this->tasks.empty()){
57 std::cout <<
"stopping worker!" << std::endl;
60 task = std::move(this->tasks.front());
77 unsigned int ThreadPool::getThreadPoolSize(){
78 #ifdef GRT_CXX11_ENABLED
79 return threadPoolSize;
86 #ifdef GRT_CXX11_ENABLED
87 threadPoolSize = threadPoolSize_;
The ThreadPool class implements a flexible inteface for performing a large number of batch tasks...
static bool setThreadPoolSize(const unsigned int threadPoolSize)