Add threadpool::invalidate function

This commit is contained in:
rexy712 2020-07-15 04:24:44 -07:00
parent 5d20755a66
commit 03e81c0457
2 changed files with 9 additions and 3 deletions

View File

@ -39,6 +39,8 @@ namespace rexy{
threadpool& operator=(const threadpool&) = delete; threadpool& operator=(const threadpool&) = delete;
threadpool& operator=(threadpool&&) = delete; threadpool& operator=(threadpool&&) = delete;
void invalidate(void);
template<class Func, class... Args> template<class Func, class... Args>
auto add_job(Func&& f, Args&&... args) -> std::future<decltype(std::forward<Func>(f)(std::forward<Args>(args)...))>; auto add_job(Func&& f, Args&&... args) -> std::future<decltype(std::forward<Func>(f)(std::forward<Args>(args)...))>;

View File

@ -48,12 +48,16 @@ namespace rexy{
m_ctor_lock.unlock(); m_ctor_lock.unlock();
} }
threadpool::~threadpool(void){ threadpool::~threadpool(void){
m_valid = false; invalidate();
//wakeup all workers and end them
m_qcv.notify_all();
for(auto& thread : m_workers){ for(auto& thread : m_workers){
thread.join(); thread.join();
} }
} }
void threadpool::invalidate(void){
m_valid = false;
//wakeup all workers and end them
m_qcv.notify_all();
}
} }