Pthread.init question

46 views
Skip to first unread message

Dieter Weidenbrück (dweidenbrueck)

unread,
Sep 15, 2023, 7:19:24 AM9/15/23
to emscripten-discuss
Hi,
I am using both pthreads and wasm workers, and I see more workers being created than necessary.
The reason seems to be the following:

PThread.init checks for ENVIRONMENT_IS_PTHREAD first, in all other cases Pthread.initMainThread is called. To me it looks like there should be an additional check for
ENVIRONMENT_IS_WASM_WORKER:

 init: function() {
  PThread.debugInit();
  if (ENVIRONMENT_IS_PTHREAD || ENVIRONMENT_IS_WASM_WORKER) {
   PThread.initWorker();
  } else {
   PThread.initMainThread();
  }
 },

The current init function leads to initMainThread being called for each wasm worker, which in turn will call PThread.init to allocate the number of workers specified by PTHREAD_POOL_SIZE multiple times..
It seems to work correctly with the suggested change, however, I am not familiar enough with the internals of Emscripten to make a judgement.

Sam Clegg

unread,
Sep 15, 2023, 11:51:23 AM9/15/23
to emscripte...@googlegroups.com
Looks like a bug.  Would you mind opening an issue on the emscripten tracker?   I don't think we do a lot of testing with wasm workers and pthreads combined like that so it's perhaps not surprising.

cheers,
sam

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/c77af58d-f543-4a98-80c5-1a855240e6e2n%40googlegroups.com.

Dieter Weidenbrück (dweidenbrueck)

unread,
Sep 17, 2023, 9:17:39 AM9/17/23
to emscripten-discuss
Reply all
Reply to author
Forward
0 new messages