From 6a37da837e1c936200f8d71a142973cc60b17b32 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 12 Aug 2020 22:13:29 +0000 Subject: threadpool: guard against exceptions in jobs, and armour plating Those would, if uncaught, exit run and leave the waiter to wait indefinitely for the number of active jobs to reach 0 --- src/common/threadpool.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/common/threadpool.h') diff --git a/src/common/threadpool.h b/src/common/threadpool.h index 91f9fdf47..66b08fece 100644 --- a/src/common/threadpool.h +++ b/src/common/threadpool.h @@ -55,12 +55,16 @@ public: class waiter { boost::mutex mt; boost::condition_variable cv; + threadpool &pool; int num; + bool error_flag; public: void inc(); void dec(); - void wait(threadpool *tpool); //! Wait for a set of tasks to finish. - waiter() : num(0){} + bool wait(); //! Wait for a set of tasks to finish, returns false iff any error + void set_error() noexcept { error_flag = true; } + bool error() const noexcept { return error_flag; } + waiter(threadpool &pool) : pool(pool), num(0), error_flag(false) {} ~waiter(); }; -- cgit v1.2.3