INCOMING_MODULE_JS_API and PThread.*

51 views
Skip to first unread message

Maksim Ivanov

unread,
Sep 8, 2023, 9:34:06 PM9/8/23
to emscripten-discuss
Hello,

Is it possible to preserve PThread.* functions, like "terminateAllThreads", on the Module object when using INCOMING_MODULE_JS_API and --closure?

I tried specifying "terminateAllThreads" or "_terminateAllThreads" or "PThread.terminateAllThreads" in -sINCOMING_MODULE_JS_API, however all of the PThread's properties seem to remain mangled.

P.S. If these functions aren't intended to be used by client code, then what would be a better way to force-shutdown pthread workers when one wants to dispose of the emscripten module instance? (It's using Embind, so exit() and friends don't seem to help.)


Thanks,
Maksim

Maksim Ivanov

unread,
Sep 8, 2023, 10:09:26 PM9/8/23
to emscripten-discuss
I guess one workaround is to inject code that creates a Module.something alias via --post-js.

But I'm still wondering whether INCOMING_MODULE_JS_API or something similar could provide a more direct way.

Sam Clegg

unread,
Sep 9, 2023, 1:54:09 AM9/9/23
to emscripte...@googlegroups.com
The `INCOMING_MODULE_JS_API` setting is designed to properties that you set on the module before its started.   Its not for exporting things.  That is what the `-sEXPORTED_FUNCTIONS` settings is for.

So you can do `-sEXPORTED_FUNCTIONS=$Pthread` but the members of that object will still be mangled so it doesn't do what you want.  You could always work around this by writing a library function that calls `PThread.terminateAllThreads` and then exporting that function.  However, as you have guessed, terminateAllThreads should be considered internal, and I think `exit()` is function you are looking for.   Perhaps there is a bug where `exit` isn't doing the right thing for you. Could you open a bug if that isn't doing what you need it to?

--
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/b93a52d7-a757-4b8d-87d6-a0ace8e3dcd4n%40googlegroups.com.

Maksim Ivanov

unread,
Sep 11, 2023, 10:36:21 AM9/11/23
to emscripten-discuss
Thank you .Filed https://github.com/emscripten-core/emscripten/issues/20225 for the worker termination thing.
Reply all
Reply to author
Forward
0 new messages