MAIN_THREAD_EM_ASM runs code on the main browser thread, regardless of where you main() is running. At least according to the docs.
I think you want to leave the ENVIRONMENT alone. USE_PTHREADS=1 should be enough. You might also want to try PROXY_TO_PTHREAD which moves your main() onto a pthread, which has some advantages (atomic wait without spinning, ability to block) and some disadvantages (many web APIs needs to me marshaled back the main web thread). On Wed, Oct 10, 2018 at 11:07 AM Hostile Fork <hostilef...@gmail.com> wrote: > > I'm trying out converting a previously-emterpreted project to the > SharedArrayBuffer and USE_PTHREADS=1. One of the first things I tried out > with that was MAIN_THREAD_EM_ASM(). > > However, ENVIRONMENT='worker', and when I use it then it still runs on the > worker. > > What I'd guess then is that "MAIN_THREAD_" refers not to the browser's UI > thread, but rather wherever the emscripten'd code was launched ("the main() > thread")? > > Because I see it runs this: > > function _emscripten_asm_const_sync_on_main_thread_i(code) { > if (ENVIRONMENT_IS_PTHREAD) { return > _emscripten_sync_run_in_browser_thread_i(-1 - code); } > return ASM_CONSTS[code](); > } > > In the debugger I see ENVIRONMENT_IS_PTHREAD is false. Naively setting > ENVIRONMENT_IS_PTHREAD doesn't work. :-) > > There are a number of settings I see regarding proxying to workers or doing a > number of other things, so I suspect what I am aiming to do is something that > people have thought of. I have a list of APIs in a `--post-js` file that I'd > like to be available on *either* the GUI thread or the worker (though the > ones that make synchronous UI requests of the browser will only be callable > from the worker, where the stack can be doing an Atomics.wait() but preserved > while the UI does its thing). > > Should I change ENVIRONMENT='web', and perhaps start by picking some other > flags? Is there an example to follow? It would be a bit of a shake-up, and > I kind of like having the loading being done on the worker how it is right > now. But if that is bucking the trend of having the hard problems solved by > someone else I can deal with changing it! > > Best, > --Brian > > -- > 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-discuss+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.