Module.oncustomMessage limitation

90 views
Skip to first unread message

Márton Marczell

unread,
Oct 20, 2021, 8:38:59 AM10/20/21
to emscripten-discuss
Hi,

Why is Module.onCustomMessage only available in PROXY_TO_WORKER mode?
Would it be possible to enable it in multi-pthreaded applications? We are in need of a solution to do custom messaging between our threads and the main thread.

Márton

Sam Clegg

unread,
Oct 28, 2021, 7:58:09 PM10/28/21
to emscripte...@googlegroups.com
We have a message queue system for sending work/functions/message between threads.  See `emscripten/threading.h`.  In particular I think `emscripten_dispatch_to_thread` might be useful to you.

Alternatively you can just use the normal C/C++ mechanisms for inter-thread communication and do it yourself.   All the standard C/C++ API for doing this kind of thing should work.


--
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-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/87bed389-c756-4bd2-9ab0-5cafcfc756ebn%40googlegroups.com.

Márton Marczell

unread,
Oct 29, 2021, 4:49:53 AM10/29/21
to emscripten-discuss

Thank you for the suggestions. My reason for asking is that our code, although mostly C++, holds on to certain resources only available by "dropping down" to JS calls, and would like to move them between workers.
We first implemented this on top of the objectTransfer message as seen in https://github.com/emscripten-core/emscripten/issues/8212, but that was undocumented, and then it got removed.


Sam Clegg

unread,
Oct 29, 2021, 6:07:25 PM10/29/21
to emscripte...@googlegroups.com
On Fri, Oct 29, 2021 at 1:49 AM 'Márton Marczell' via emscripten-discuss <emscripte...@googlegroups.com> wrote:

Thank you for the suggestions. My reason for asking is that our code, although mostly C++, holds on to certain resources only available by "dropping down" to JS calls, and would like to move them between workers.
We first implemented this on top of the objectTransfer message as seen in https://github.com/emscripten-core/emscripten/issues/8212, but that was undocumented, and then it got removed.


So you want to not only run code on a certain thread but also transfer over JS objects to the target thread?   Thats hard in the general case because postMessage messages only occur when a thread yeilds to the event loop, and pthreads don't normally do that.    Is there some way you can restructure your application to use native heap objects rather than JS objects?

 

On Friday, 29 October 2021 at 01:58:09 UTC+2 s...@google.com wrote:
We have a message queue system for sending work/functions/message between threads.  See `emscripten/threading.h`.  In particular I think `emscripten_dispatch_to_thread` might be useful to you.

Alternatively you can just use the normal C/C++ mechanisms for inter-thread communication and do it yourself.   All the standard C/C++ API for doing this kind of thing should work.


On Wed, Oct 20, 2021 at 5:39 AM 'Márton Marczell' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
Hi,

Why is Module.onCustomMessage only available in PROXY_TO_WORKER mode?
Would it be possible to enable it in multi-pthreaded applications? We are in need of a solution to do custom messaging between our threads and the main thread.

Márton

--
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-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/87bed389-c756-4bd2-9ab0-5cafcfc756ebn%40googlegroups.com.

--
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-disc...@googlegroups.com.

Márton Marczell

unread,
Mar 23, 2022, 10:24:15 AM3/23/22
to emscripten-discuss
Just for posterity: We managed to put all operations manipulating JS objects (such as Blobs) on one thread and get rid of this requirement.
Reply all
Reply to author
Forward
0 new messages