diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index bf8b65b7af6ef..132faf1d0b06f 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -117,7 +117,7 @@ function run() { #endif function initRuntime(wasmExports) { -#if ASSERTIONS || SAFE_HEAP || USE_ASAN || MODULARIZE +#if ASSERTIONS || SAFE_HEAP || USE_ASAN || MODULARIZE || PTHREADS runtimeInitialized = true; #endif diff --git a/src/runtime_common.js b/src/runtime_common.js index 23a3915cb14cc..aea1cefcef55d 100644 --- a/src/runtime_common.js +++ b/src/runtime_common.js @@ -80,7 +80,7 @@ if (ENVIRONMENT_IS_NODE && {{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) { var HEAP_DATA_VIEW; #endif -#if !MINIMAL_RUNTIME || ASSERTIONS || SAFE_HEAP || USE_ASAN || MODULARIZE +#if !MINIMAL_RUNTIME || ASSERTIONS || SAFE_HEAP || USE_ASAN || MODULARIZE || PTHREADS var runtimeInitialized = false; #endif diff --git a/src/runtime_pthread.js b/src/runtime_pthread.js index 9423a22822487..69023d15a3408 100644 --- a/src/runtime_pthread.js +++ b/src/runtime_pthread.js @@ -131,6 +131,9 @@ if (ENVIRONMENT_IS_PTHREAD) { } else if (cmd == {{{ CMD_RUN }}}) { #if ASSERTIONS assert(msgData.pthread_ptr); +#if !WASM_ESM_INTEGRATION + assert(wasmMemory, "CMD_RUN received before CMD_LOAD"); +#endif #endif // Call inside JS module to set up the stack frame for this pthread in JS module scope. // This needs to be the first thing that we do, as we cannot call to any C/C++ functions @@ -190,7 +193,7 @@ if (ENVIRONMENT_IS_PTHREAD) { err(`worker: onmessage() captured an uncaught exception: ${ex}`); if (ex?.stack) err(ex.stack); #endif - __emscripten_thread_crashed(); + if (runtimeInitialized) __emscripten_thread_crashed(); throw ex; } }; diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index a60cc29cf4110..d0c9cb6e314ee 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 6949, - "a.out.js.gz": 3427, + "a.out.js": 6969, + "a.out.js.gz": 3438, "a.out.nodebug.wasm": 19063, "a.out.nodebug.wasm.gz": 8803, - "total": 26012, - "total_gz": 12230, + "total": 26032, + "total_gz": 12241, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index ad0524a4dd8a1..177e08d93e5b5 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 7357, - "a.out.js.gz": 3627, + "a.out.js": 7377, + "a.out.js.gz": 3640, "a.out.nodebug.wasm": 19064, "a.out.nodebug.wasm.gz": 8804, - "total": 26421, - "total_gz": 12431, + "total": 26441, + "total_gz": 12444, "sent": [ "a (memory)", "b (exit)",