1 #define GRT_DLL_EXPORTS 7 #ifdef GRT_CXX11_ENABLED 9 std::atomic< unsigned int > ThreadPool::threadPoolSize( std::thread::hardware_concurrency() );
14 #ifdef GRT_CXX11_ENABLED 16 launchThreads( threadPoolSize );
22 #ifdef GRT_CXX11_ENABLED 24 launchThreads( poolSize );
31 std::cout <<
"~ThreadPool()\n";
32 #ifdef GRT_CXX11_ENABLED 34 condition.notify_all();
35 for(std::thread &worker: workers)
40 #ifdef GRT_CXX11_ENABLED 41 void ThreadPool::launchThreads(
const unsigned int poolSize ){
44 for(
unsigned int i = 0; i<poolSize; ++i)
50 std::function< void() > task;
54 std::unique_lock<std::mutex> lock(this->queue_mutex);
55 this->condition.wait(lock,
56 [this]{ return this->stop || !this->tasks.empty(); });
57 if(this->stop && this->tasks.empty()){
58 std::cout <<
"stopping worker!" << std::endl;
61 task = std::move(this->tasks.front());
79 #ifdef GRT_CXX11_ENABLED 80 return threadPoolSize;
87 #ifdef GRT_CXX11_ENABLED 88 threadPoolSize = threadPoolSize_;
static unsigned int getThreadPoolSize()
The ThreadPool class implements a flexible inteface for performing a large number of batch tasks...
static bool setThreadPoolSize(const unsigned int threadPoolSize)