mirror of
https://github.com/monero-project/monero.git
synced 2025-08-13 06:15:31 -04:00
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:
parent
5d850dde99
commit
6a37da837e
8 changed files with 72 additions and 60 deletions
|
@ -120,7 +120,7 @@ threadpool::waiter::~waiter()
|
|||
catch (...) { /* ignore */ }
|
||||
try
|
||||
{
|
||||
wait(NULL);
|
||||
wait();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
@ -128,12 +128,12 @@ threadpool::waiter::~waiter()
|
|||
}
|
||||
}
|
||||
|
||||
void threadpool::waiter::wait(threadpool *tpool) {
|
||||
if (tpool)
|
||||
tpool->run(true);
|
||||
bool threadpool::waiter::wait() {
|
||||
pool.run(true);
|
||||
boost::unique_lock<boost::mutex> lock(mt);
|
||||
while(num)
|
||||
cv.wait(lock);
|
||||
return !error();
|
||||
}
|
||||
|
||||
void threadpool::waiter::inc() {
|
||||
|
@ -166,7 +166,8 @@ void threadpool::run(bool flush) {
|
|||
lock.unlock();
|
||||
++depth;
|
||||
is_leaf = e.leaf;
|
||||
e.f();
|
||||
try { e.f(); }
|
||||
catch (const std::exception &ex) { e.wo->set_error(); try { MERROR("Exception in threadpool job: " << ex.what()); } catch (...) {} }
|
||||
--depth;
|
||||
is_leaf = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue