diff --git a/src/library_pthread.js b/src/library_pthread.js index dda54a72c37e0..20d9a0ce5ddee 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -405,7 +405,7 @@ var LibraryPThread = { #if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER // This is the way that we signal to the Web Worker that it is hosting // a pthread. - 'name': 'em-pthread', + 'name': 'em-pthread_' + PThread.nextWorkerID, #endif }; #if EXPORT_ES6 && USE_ES6_IMPORT_META diff --git a/src/shell.js b/src/shell.js index 104ceb4ce9b1b..feb09c3228cbd 100644 --- a/src/shell.js +++ b/src/shell.js @@ -118,7 +118,7 @@ if (Module['ENVIRONMENT']) { // The way we signal to a worker that it is hosting a pthread is to construct // it with a specific name. -var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread'; +var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name.startsWith('em-pthread_'); #if MODULARIZE && ASSERTIONS if (ENVIRONMENT_IS_PTHREAD) { diff --git a/src/shell_minimal.js b/src/shell_minimal.js index 7567843242bf3..290a2c3bb1ccf 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -138,7 +138,7 @@ function ready() { // MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments // coincide. var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function'; -var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread'; +var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name.startsWith('em-pthread_'); #if !MODULARIZE // In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there diff --git a/tools/link.py b/tools/link.py index 7b14a75e7cf7e..9a6e642510579 100644 --- a/tools/link.py +++ b/tools/link.py @@ -2445,7 +2445,7 @@ def modularize(): # when running in MODULARIZE mode we need use this to know if we should # run the module constructor on startup (true only for pthreads). if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER: - src += "var isPthread = globalThis.self?.name === 'em-pthread';\n" + src += "var isPthread = globalThis.self?.name.startsWith('em-pthread_');\n" # In order to support both web and node we also need to detect node here. if settings.ENVIRONMENT_MAY_BE_NODE: src += "var isNode = typeof globalThis.process?.versions?.node == 'string';\n"