diff --git a/include/rexy/threadpool.hpp b/include/rexy/threadpool.hpp index 0f50913..82c108f 100644 --- a/include/rexy/threadpool.hpp +++ b/include/rexy/threadpool.hpp @@ -39,6 +39,8 @@ namespace rexy{ threadpool& operator=(const threadpool&) = delete; threadpool& operator=(threadpool&&) = delete; + void invalidate(void); + template auto add_job(Func&& f, Args&&... args) -> std::future(f)(std::forward(args)...))>; diff --git a/src/threadpool.cpp b/src/threadpool.cpp index b6ec39e..5d260a2 100644 --- a/src/threadpool.cpp +++ b/src/threadpool.cpp @@ -48,12 +48,16 @@ namespace rexy{ m_ctor_lock.unlock(); } threadpool::~threadpool(void){ - m_valid = false; - //wakeup all workers and end them - m_qcv.notify_all(); + invalidate(); for(auto& thread : m_workers){ thread.join(); } } + void threadpool::invalidate(void){ + m_valid = false; + //wakeup all workers and end them + m_qcv.notify_all(); + } + }