diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-10-02 10:59:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-02 10:59:28 -0700 |
commit | 2ec15bea0c5b7d4112e06fadcc3a531f303d4a4c (patch) | |
tree | e1d52311bf0b91b8d618750cedcba674e7e1bbef /src/support/threads.cpp | |
parent | ee9d515581998165c0e573d2b5a468c5b361cfcd (diff) | |
download | binaryen-2ec15bea0c5b7d4112e06fadcc3a531f303d4a4c.tar.gz binaryen-2ec15bea0c5b7d4112e06fadcc3a531f303d4a4c.tar.bz2 binaryen-2ec15bea0c5b7d4112e06fadcc3a531f303d4a4c.zip |
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
Diffstat (limited to 'src/support/threads.cpp')
-rw-r--r-- | src/support/threads.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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<Thread>()); + try { + threads.emplace_back(make_unique<Thread>()); + } 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(); }); |