From dd290bd26a89bb2974755135724f2d22b32aaf30 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 23 Jul 2021 15:03:04 +0200 Subject: [PATCH 1/2] Remove early return from `exitRuntime()`. NFC `exitRuntime()` is never called when `ENVIRONMENT_IS_PTHREAD` is true. --- src/preamble.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/preamble.js b/src/preamble.js index 0d37997e53e50..3a823d2a3343f 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -209,7 +209,6 @@ function exitRuntime() { #if STACK_OVERFLOW_CHECK checkStackCookie(); #endif - {{{ runIfWorkerThread('return;') }}} // PThreads reuse the runtime from the main thread. #if !STANDALONE_WASM ___funcs_on_exit(); // Native atexit() functions #endif From 3363b04dad04732165cf45a2cc8dd45d031d9e43 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 5 May 2026 18:09:16 +0200 Subject: [PATCH 2/2] Add assertion --- src/preamble.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/preamble.js b/src/preamble.js index 3a823d2a3343f..b039a508fac0a 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -201,6 +201,9 @@ function exitRuntime() { assert(!runtimeExited); assert(!runtimeExiting, 'Re-entrant call to exitRuntime()! This can happen if an atexit() registered callback throws an exception.'); runtimeExiting = true; +#if PTHREADS || WASM_WORKERS + assert(!{{{ ENVIRONMENT_IS_WORKER_THREAD() }}}, 'exitRuntime() should only be called from the main thread'); +#endif #endif #if ASYNCIFY == 1 && ASSERTIONS // ASYNCIFY cannot be used once the runtime starts shutting down.