hi sam,

thanks for your thought; in the end I sticked to MAIN_THREAD_EM_ASM,
because it meant I could just pass on a stack allocated structure. so
far there wasn't any perceivable performance problem that would require
me to switch to asynchronous invocation.

best, .h.h.


On 06/01/2021 13:38, 'Sam Clegg' via emscripten-discuss wrote:
> 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]
> <mailto:[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]
>     <mailto:emscripten-discuss%[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
>     
> <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]
> <mailto:[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
> <https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-SE0rq8c5Sok4T6VPiohczkJ%3D4%3DOwoQfqkqskZOVj%3Dmw%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/811c47e8-8d15-a42e-0b16-8b29ed1a710c%40sciss.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to