Skip to content

Commit 33665b6

Browse files
authored
Don't call static desructors when Fatal() errors occur (#1722)
This was causing a deadlock while destroying the thread pool.
1 parent 0ed4d2f commit 33665b6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/support/threads.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void ThreadPool::initialize(size_t num) {
128128
}
129129

130130
size_t ThreadPool::getNumCores() {
131-
#if EMSCRIPTEN
131+
#ifdef __EMSCRIPTEN__
132132
return 1;
133133
#else
134134
size_t num = std::max(1U, std::thread::hardware_concurrency());
@@ -181,7 +181,7 @@ void ThreadPool::work(std::vector<std::function<ThreadWorkState ()>>& doWorkers)
181181
}
182182
DEBUG_POOL("main thread waiting\n");
183183
condition.wait(lock, [this]() { return areThreadsReady(); });
184-
DEBUG_POOL("main thread waiting\n");
184+
DEBUG_POOL("main thread done waiting\n");
185185
DEBUG_POOL("running = false\n");
186186
running = false;
187187
DEBUG_POOL("work() is done\n");

src/support/utilities.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ class Fatal {
7171
}
7272
WASM_NORETURN ~Fatal() {
7373
std::cerr << "\n";
74-
exit(1);
74+
// Use _Exit here to avoid calling static destructors. This avoids deadlocks
75+
// in (for example) the thread worker pool, where workers hold a lock while
76+
// performing their work.
77+
_Exit(1);
7578
}
7679
};
7780

0 commit comments

Comments
 (0)