I think MAIN_THREAD_ASYNC_EM_ASM is what you want.     malloc and free work
both in C++ and in JS just the same and across threads just fine.

Alternatively you could call the C++ function on the main thread using
`emscripten_async_run_in_main_runtime_thread` and then once that function
is running on the main thread call out ot EM_ASM or other JS library
function as needed.

On Thu, Dec 31, 2020 at 4:21 AM Hanns Holger Rutz <[email protected]> wrote:

> Hi there,
>
> I wonder what is the best way to pass a byte array from non-main-thread
> C++ to main-thread JS. I'm hesitating to call MAIN_THREAD_SYNC_EM_ASM
> because I don't want to block the C++ thread. So the next two options
> are EM_ASM and MAIN_THREAD_ASYNC_EM_ASM. In the asynchronous case,
> obviously I would have to malloc in C++ and free in JS. Is that
> possible? In the EM_ASM case, JS doesn't have access to any regular
> objects from the main JS environment. So I would have to copy the data
> and defer to the main JS thread? I suppose there is one worker.js that I
> would have to listen to from main, and use postMessage from within EM_ASM?
>
> Also the data is bounded by 8K, could I perhaps use a different
> approach, like use a constant size array direct passing somehow?
>
> best, .h.h.
>
> --
> 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 on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/52f2a4ac-2baa-8d90-1486-c5adc57873f4%40sciss.de
> .
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-SE0rq8c5Sok4T6VPiohczkJ%3D4%3DOwoQfqkqskZOVj%3Dmw%40mail.gmail.com.

Reply via email to