Hello,

I thought, I was supposed to load it only in a worker... That's because of 
examples, I guess.

Can I load it in the main browser page without side-effects? (assuming that 
there's no blocking stuff )? :)

Kind regards,
Ilya Kantor

> On 9 Feb 2023, at 20:37, 'Sam Clegg' via emscripten-discuss 
> <emscripten-discuss@googlegroups.com> wrote:
> 
> The term "main thread" can be ambiguous and confusing I'm afraid.
> 
> In emscripten we disambiguate we have two concepts of `main` thread.
> 
> 1. The main browser thread (i.e. not a worker)
> 2. The main emscripten runtime thread (the thread where the emscripten module 
> get first loaded).
> 
> Normally on the web these two are the same thing since the emscripten module 
> gets instantiated on the main browser thread.  However if you load the 
> emscripten module on a worker, then there will be no main browser thread, or 
> at leat no main browser thread that is accessible to emscripten.
> 
> When we say "proxy to main thread" or "MAIN_THREAD_EM_ASM" we are always 
> talking about the main runtime thread, since that is the only thing that is 
> guaranteed to exist.
> 
> There are many APIs which won't work if your main runtime thread is not also 
> the main browser thread (e.g anything related to the DOM).
> 
> Note: I myself have been confused about these concepts in the past, and my 
> knowledge could still have gaps but that is my understanding today.
> 
> cheers,
> sam
> 
> 
> 
> On Thu, Feb 9, 2023 at 12:18 AM Ilya Kantor <ilia...@gmail.com 
> <mailto:ilia...@gmail.com>> wrote:
>> Hello,
>> 
>> I'm reading the docs and getting confused, what the "Main thread" is?
>> 
>> Sometimes it's referred to as the "Main browser thread", the term appears in 
>> macroses such as MAIN_THREAD_EM_ASM.
>> 
>> I see two possible explanations there, please tell me which one is correct?
>> 
>> 1) The "main thread" is the main browser page thread that loaded WASM 
>> webworker, the one with the "window" object. It has access to DOM etc. So we 
>> can use it to work from DOM from C.
>> 
>> It appears so from the page: 
>> https://emscripten.org/docs/api_reference/emscripten.h.html?highlight=main_thread_async_em_asm#c.MAIN_THREAD_EM_ASM
>> 
>> But it doesn't work for me like that, and I don't see any `postMessage` 
>> calls in JS,  how does Emscripten implement the interaction with the main 
>> page?
>> 
>> 2) The "main thread" is related to pthread usage: it's the all-parenting 
>> pthread, when we have multiple pthreads running. Otherwise, if we're not 
>> using pthreads, then it's irrelevant, the main thread is the only thread 
>> anyway.
>> 
>> In other words, the "main thread" is a pure pthreads concept, the 
>> all-parenting thread.
>> 
>> 3) ...Can it be sometimes 1) and sometimes 2)? =)
>> 
>> Please help me to figure out.
>> 
>> Thank you!
>> 
>> Kind regards,
>> Ilya Kantor
>> 
>> -- 
>> 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 
>> <mailto:emscripten-discuss+unsubscr...@googlegroups.com>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/emscripten-discuss/029031da-a7f9-47dc-8db0-91a52672e9aan%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/emscripten-discuss/029031da-a7f9-47dc-8db0-91a52672e9aan%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 
> 
> -- 
> 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 
> <mailto:emscripten-discuss+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28pE4CHpBr3h-6oGekgHtcnufajCPV08vCZSmr3kcA0KQ%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28pE4CHpBr3h-6oGekgHtcnufajCPV08vCZSmr3kcA0KQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/8A552383-110C-4002-9BD8-169CF212FDC9%40gmail.com.

Reply via email to