Skip to content
Snippets Groups Projects
Commit 41eabc72 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

thread pool: handle exceptions starting threads

parent 424fe61a
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,7 @@ ThreadPool::run(std::function<void()>&& cb) ...@@ -65,6 +65,7 @@ ThreadPool::run(std::function<void()>&& cb)
// launch new thread if necessary // launch new thread if necessary
if (not readyThreads_ && threads_.size() < maxThreads_) { if (not readyThreads_ && threads_.size() < maxThreads_) {
try {
threads_.emplace_back(std::make_unique<std::thread>([this]() { threads_.emplace_back(std::make_unique<std::thread>([this]() {
while (true) { while (true) {
std::function<void()> task; std::function<void()> task;
...@@ -92,6 +93,11 @@ ThreadPool::run(std::function<void()>&& cb) ...@@ -92,6 +93,11 @@ ThreadPool::run(std::function<void()>&& cb)
} }
} }
})); }));
} catch(const std::exception& e) {
std::cerr << "Exception starting thread: " << e.what() << std::endl;
if (threads_.empty())
throw;
}
} }
// push task to queue // push task to queue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment