From 2ec15bea0c5b7d4112e06fadcc3a531f303d4a4c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 2 Oct 2017 10:59:28 -0700 Subject: Thread fixes (#1205) * don't use multiple threads in torture tests, which are parallel anyhow * if we fail to create a thread, don't use multiple threads --- src/support/threads.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/support/threads.cpp') diff --git a/src/support/threads.cpp b/src/support/threads.cpp index 3e32ffb15..31c900ceb 100644 --- a/src/support/threads.cpp +++ b/src/support/threads.cpp @@ -111,7 +111,14 @@ void ThreadPool::initialize(size_t num) { ready.store(threads.size()); // initial state before first resetThreadsAreReady() resetThreadsAreReady(); for (size_t i = 0; i < num; i++) { - threads.emplace_back(make_unique()); + try { + threads.emplace_back(make_unique()); + } catch (std::system_error&) { + // failed to create a thread - don't use multithreading, as if num cores == 1 + DEBUG_POOL("could not create thread\n"); + threads.clear(); + return; + } } DEBUG_POOL("initialize() waiting\n"); condition.wait(lock, [this]() { return areThreadsReady(); }); -- cgit v1.2.3