From 03e81c0457e935d8c0a9eba371de4f100c2343c4 Mon Sep 17 00:00:00 2001 From: rexy712 Date: Wed, 15 Jul 2020 04:24:44 -0700 Subject: [PATCH] Add threadpool::invalidate function --- include/rexy/threadpool.hpp | 2 ++ src/threadpool.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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(); + } + }