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) -> std::future<std::invoke_result_t<Function, Arguments...>>
89 using return_type = std::invoke_result_t<Function, Arguments...>;
92 auto task = std::make_shared<std::packaged_task<return_type()>>(
93 [
function, arguments...]() -> return_type {
return function(arguments...); });
95 std::future<return_type> res = task->get_future();
97 const std::lock_guard<std::mutex> lockGuard(this->GetMutex());
98 m_WorkQueue.emplace_back([task]() { (*task)(); });
100 m_Condition.notify_one();
111 const std::lock_guard<std::mutex> lockGuard(this->GetMutex());
112 return static_cast<ThreadIdType>(m_Threads.size());
117 GetNumberOfCurrentlyIdleThreads()
const;
124 GetDoNotWaitForThreads();
126 SetDoNotWaitForThreads(
bool doNotWaitForThreads);
166 bool m_Stopping{
false };