Skip to content

Commit

Permalink
Don't call static desructors when Fatal() errors occur (#1722)
Browse files Browse the repository at this point in the history
This was causing a deadlock while destroying the thread pool.
  • Loading branch information
sbc100 authored Nov 2, 2018
1 parent 0ed4d2f commit 33665b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/support/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void ThreadPool::initialize(size_t num) {
}

size_t ThreadPool::getNumCores() {
#if EMSCRIPTEN
#ifdef __EMSCRIPTEN__
return 1;
#else
size_t num = std::max(1U, std::thread::hardware_concurrency());
Expand Down Expand Up @@ -181,7 +181,7 @@ void ThreadPool::work(std::vector<std::function<ThreadWorkState ()>>& doWorkers)
}
DEBUG_POOL("main thread waiting\n");
condition.wait(lock, [this]() { return areThreadsReady(); });
DEBUG_POOL("main thread waiting\n");
DEBUG_POOL("main thread done waiting\n");
DEBUG_POOL("running = false\n");
running = false;
DEBUG_POOL("work() is done\n");
Expand Down
5 changes: 4 additions & 1 deletion src/support/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ class Fatal {
}
WASM_NORETURN ~Fatal() {
std::cerr << "\n";
exit(1);
// Use _Exit here to avoid calling static destructors. This avoids deadlocks
// in (for example) the thread worker pool, where workers hold a lock while
// performing their work.
_Exit(1);
}
};

Expand Down

0 comments on commit 33665b6

Please sign in to comment.