18 #ifndef itkThreadPool_h
19 #define itkThreadPool_h
21 #include "itkConfigure.h"
27 #include <condition_variable>
53 struct ThreadPoolGlobals;
85 template <
class Function,
class... Arguments>
87 AddWork(Function &&
function, Arguments &&... arguments)
88 -> std::future<
typename std::result_of<Function(Arguments...)>::type>
90 using return_type =
typename std::result_of<Function(Arguments...)>::type;
93 auto task = std::make_shared<std::packaged_task<return_type()>>(
94 std::bind(std::forward<Function>(
function), std::forward<Arguments>(arguments)...));
96 std::future<return_type> res = task->get_future();
98 std::unique_lock<std::mutex> lock(this->GetMutex());
99 m_WorkQueue.emplace_back([task]() { (*task)(); });
101 m_Condition.notify_one();
112 return static_cast<ThreadIdType>(m_Threads.size());
117 GetNumberOfCurrentlyIdleThreads()
const;
124 GetDoNotWaitForThreads();
126 SetDoNotWaitForThreads(
bool doNotWaitForThreads);
156 bool m_Stopping{
false };