From 41a390625d5be5f71b47c02488c0fa01d39da268 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 9 Sep 2024 14:14:04 -0700 Subject: [PATCH] Reset `noExitRuntime` every time a new pthread starts Previously we were only setting this value when a worker was first created. This means that changes to this value could persist between pthreads. --- src/library_pthread.js | 25 ++++++++----------- .../test_codesize_minimal_pthreads.gzsize | 2 +- .../test_codesize_minimal_pthreads.jssize | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/library_pthread.js b/src/library_pthread.js index 956413960afb3..8a8c92a673662 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -94,8 +94,6 @@ var LibraryPThread = { #endif if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) { PThread.initMainThread(); - } else { - PThread.initWorker(); } }, initMainThread() { @@ -122,19 +120,6 @@ var LibraryPThread = { #endif }, - initWorker() { -#if isSymbolNeeded('$noExitRuntime') - // The default behaviour for pthreads is always to exit once they return - // from their entry point (or call pthread_exit). If we set noExitRuntime - // to true here on pthreads they would never complete and attempt to - // pthread_join to them would block forever. - // pthreads can still choose to set `noExitRuntime` explicitly, or - // call emscripten_unwind_to_js_event_loop to extend their lifetime beyond - // their main function. See comment in src/runtime_pthread.js for more. - noExitRuntime = false; -#endif - }, - #if PTHREADS_PROFILING getThreadName(pthreadPtr) { var profilerBlock = {{{ makeGetValue('pthreadPtr', C_STRUCTS.pthread.profilerBlock, '*') }}}; @@ -1066,6 +1051,16 @@ var LibraryPThread = { // `runtimeKeepaliveCounter` to zero. Reset it now so the new thread won't // be affected. runtimeKeepaliveCounter = 0; + +#if isSymbolNeeded('$noExitRuntime') + // Same for noExitRuntime. The default for pthreads should always be false + // otherwise pthreads would never complete and attempts to pthread_join to + // them would block forever. + // pthreads can still choose to set `noExitRuntime` explicitly, or + // call emscripten_unwind_to_js_event_loop to extend their lifetime beyond + // their main function. See comment in src/runtime_pthread.js for more. + noExitRuntime = 0; +#endif #endif #if MAIN_MODULE diff --git a/test/other/codesize/test_codesize_minimal_pthreads.gzsize b/test/other/codesize/test_codesize_minimal_pthreads.gzsize index d344ba0896151..e8df1295e424f 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.gzsize +++ b/test/other/codesize/test_codesize_minimal_pthreads.gzsize @@ -1 +1 @@ -5015 +5012 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.jssize b/test/other/codesize/test_codesize_minimal_pthreads.jssize index 04fd0f2f6c30f..59d611637cf1c 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.jssize +++ b/test/other/codesize/test_codesize_minimal_pthreads.jssize @@ -1 +1 @@ -10827 +10825