Hi Phil,

Glad you figured this out. Using your own proxying queue sounds exactly
like what you need. It's a good question about whether
MAIN_THREAD_ASYNC_EM_ASM and other user-facing features should use the
system queue. Those features predate the current proxying queue API and
when they were introduced the system queue was the only queue available. As
you've noticed it can be unsafe to use the system queue for some kinds of
work, so it might be reasonable to make MAIN_THREAD_ASYNC_EM_ASM and
friends use a separate, dedicated proxying queue, but that would be an
observable change.

+Sam Clegg <[email protected]>, WDYT about changing to use a dedicated queue
for those older APIs?

Thomas

On Sat, Aug 30, 2025 at 8:34 AM 'Phil Endecott' via emscripten-discuss <
[email protected]> wrote:

> 'Phil Endecott' via emscripten-discuss wrote:
> > So - is there some alternative to MAIN_THREAD_ASYNC_EM_ASM
> > that I should use, such that the work is only done when the main
> > thread is actually idle?
>
> It seems that the solution is to create a new emscripten::ProxyingQueue
> and add my work to that.
>
> I had previously discounted using that, because I thought that I would
> need to arrange to call execute() myself somehow. But that is not the
> case:
>
> - All queues are run when their thread is idle; the web workers
> postMessage/onMessage mechanism is used to make that happen.
>
> - The "system queue" is additionally run from the yeild() function,
> which is called by f/mutex_lock when it blocks.
>
> - MAIN_THREAD_ASYNC_EM_ASM uses the "system queue".
>
> I'm not convinced that having the user-facing
> MAIN_THREAD_ASYNC_EM_ASM feature use this special queue
> is the right thing to do; wouldn't it be better if it used its own
> queue that only ran when the main thread is idle?
>
> Anyway, I now have this working.
>
>
> Regards, Phil.
>
>
>
>
>
>
>
> --
> 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 [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/emscripten-discuss/1756567907739%40dmwebmail.dmwebmail.chezphil.org
> .
>

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAJZD_EW7HBF%3D5tcgsKcKg5f7BZMstvifMvUCS9JrP_EFXouw5A%40mail.gmail.com.

Reply via email to