Is my application single- or multi-threaded?

36 views
Skip to first unread message

Simon Sandström

unread,
Oct 2, 2019, 8:28:23 AM10/2/19
to emscripte...@googlegroups.com
Hello,

I have an application that first creates and setups a WebSocket, like
this:

ws = emscripten::val::global("WebSocket").new_(emscripten::val(...));
ws.set("onopen", emscripten::val::module_property("onopen"));
ws.set("onmessage", emscripten::val::module_property("onmessage"));

and then it sets a main loop with emscripten_set_main_loop(...).
Everything works fine right now as there are no shared resouces between
onopen/onmessage and the code that is run in the main loop, but in the
future it will be.

Is my application multi-threaded? Can the onopen/onmessage event fire
and execute at the same time as my main loop? Answers online are mostly
old and says that there are no multi-threading in browser JavaScript,
but what about web workers? Are they involved in this scenario?


- Simon

Derek Schuff

unread,
Oct 3, 2019, 1:07:38 PM10/3/19
to emscripten-discuss
Unless you are using the -s USE_PTHREADS flag, then your application is not mult-threaded. So the browser main thread event loop is driving everything, and there shouldn't be events firing simultaneously. There's only a web worker if you create the worker yourself and instantiate the emscripten module on that worker (and if you do that, there's a completely separate JS/wasm environment that's not shared with the main-thread environment).

--
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/20191002122818.7pjxllqnqrc3nayz%40simon-laptop.
Reply all
Reply to author
Forward
0 new messages