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
This commit is contained in:
moneromooo-monero 2020-08-12 22:13:29 +00:00
parent 5d850dde99
commit 6a37da837e
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
8 changed files with 72 additions and 60 deletions

View file

@ -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();
};