Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document MAIN_THREAD_EM_ASM and variants #9941

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions site/source/docs/api_reference/emscripten.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,33 @@ Defines

Similar to :c:macro:`EM_ASM_INT` but for a ``double`` return value.

.. c:macro:: MAIN_THREAD_EM_ASM(code, ...)

This behaves like :c:macro:`EM_ASM`, but does the call on the main thread. This is
useful in a pthreads build, when you want to interact with the DOM from a
pthread; this basically proxies the call for you.

This call is proxied in a synchronous way to the main thread, that is,
execution will resume after the main thread has finished running the JS.
Synchronous proxying also makes it possible to return a value, see the next
two variants.

.. c:macro:: MAIN_THREAD_EM_ASM_INT(code, ...)

Similar to :c:macro:`MAIN_THREAD_EM_ASM` but returns an ``int`` value.

.. c:macro:: MAIN_THREAD_EM_ASM_DOUBLE(code, ...)

Similar to :c:macro:`MAIN_THREAD_EM_ASM` but returns a ``double`` value.

.. c:macro:: MAIN_THREAD_ASYNC_EM_ASM(code, ...)

Similar to :c:macro:`MAIN_THREAD_EM_ASM` but is proxied in an
**asynchronous** way, that is, the main thread will receive a request to run
the code, and will run it when it can; the worker will not wait for that.
(Note that if this is called on the main thread, then there is nothing to
proxy, and the JS is executed immediately and synchronously.)


Calling JavaScript From C/C++
=============================
Expand Down