9 #ifndef KNOWROB_THREAD_POOL_H_
10 #define KNOWROB_THREAD_POOL_H_
17 #include <condition_variable>
150 class LambdaRunner :
public Runner {
172 std::list<Worker *> workerThreads_;
174 std::queue<std::shared_ptr<ThreadPool::Runner>> workQueue_;
176 std::condition_variable workCV_;
177 mutable std::mutex workMutex_;
179 uint32_t maxNumThreads_;
181 std::atomic_uint32_t numFinishedThreads_;
183 std::atomic_uint32_t numActiveWorker_;
186 std::shared_ptr<ThreadPool::Runner> popWork();
189 virtual bool initializeWorker() {
return true; }
std::function< bool()> StopChecker
LambdaRunner(const std::function< void(const StopChecker &)> &fn)
std::function< void(const StopChecker &)> fn_
std::atomic< bool > hasStopRequest_
bool isTerminated() const
void setExceptionHandler(ExceptionHandler exceptionHandler)
std::atomic< bool > isRunning_
std::condition_variable finishedCV_
std::atomic< bool > isTerminated_
ExceptionHandler exceptionHandler_
bool hasStopRequest() const
Runner(const Runner &)=delete
Worker(ThreadPool *thread_pool)
std::atomic< bool > hasTerminateRequest_
std::atomic< bool > isTerminated_
Worker(const Worker &)=delete
void pushWork(const std::shared_ptr< ThreadPool::Runner > &goal, ThreadPool::ExceptionHandler exceptionHandler)
std::function< void(const std::exception &)> ExceptionHandler
std::function< void()> finalizeWorker_
ThreadPool(const ThreadPool &)=delete
ThreadPool(uint32_t maxNumThreads)
FunctionRule & function()
std::shared_ptr< ThreadPool > DefaultThreadPool()