From c1b523d64253b88cb87cb0d7363128e7425e9030 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Fri, 25 Jul 2014 23:24:04 -0700 Subject: [PATCH] feat(util/worker_queue): allow main thread to process tasks while waiting Signed-off-by: Leonardo de Moura --- src/util/worker_queue.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/util/worker_queue.h b/src/util/worker_queue.h index b321faf08..050407771 100644 --- a/src/util/worker_queue.h +++ b/src/util/worker_queue.h @@ -101,9 +101,20 @@ public: } m_todo.clear(); } else { - m_todo_cv.notify_all(); - for (thread_ptr & t : m_threads) - t->join(); + try { + while (auto t = next_task()) { + add_result((*t)()); + } + m_todo_cv.notify_all(); + for (thread_ptr & t : m_threads) + t->join(); + } catch (...) { + for (auto & th : m_threads) + th->request_interrupt(); + for (auto & th : m_threads) + th->join(); + throw; + } if (m_failed_thread >= 0) m_thread_exceptions[m_failed_thread]->rethrow(); if (m_interrupted)