Commit b757b7eb authored by Paul Asmuth's avatar Paul Asmuth
Browse files

better error handling in ThreadPool

parent 1819132a
Loading
Loading
Loading
Loading
+28 −24
Original line number Diff line number Diff line
@@ -92,8 +92,10 @@ void ThreadPool::runInternal(std::function<void()> fn) {
}

void ThreadPool::startThread() {
  try {
    std::thread thread([this] () {
      for (;;) {
        try {
          std::function<void()> task;

          {
@@ -110,7 +112,6 @@ void ThreadPool::startThread() {
            free_threads_--;
          }

      try {
          task();
        } catch (const std::exception& e) {
          this->error_handler_->onException(e);
@@ -119,6 +120,9 @@ void ThreadPool::startThread() {
    });

    thread.detach();
  } catch (const std::exception& e) {
    this->error_handler_->onException(e);
  }
}