From 641007587150851459040550d68f5f2128a3e071 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 19 Oct 2020 10:06:28 -0700 Subject: [PATCH 1/2] Document pthread ordering of sync/async commands [ci skip] --- system/include/emscripten/threading.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/include/emscripten/threading.h b/system/include/emscripten/threading.h index aaf02b0b2bb23..f26f3ed09d976 100644 --- a/system/include/emscripten/threading.h +++ b/system/include/emscripten/threading.h @@ -310,6 +310,11 @@ int emscripten_sync_run_in_main_runtime_thread_(EM_FUNC_SIGNATURE sig, void *fun // - Note that multiple asynchronous commands from a single pthread/Worker are // guaranteed to be executed on the main thread in the program order they // were called in. +// - Note that synchronous and asynchronous commands are *also* guaranteed to +// be executed in order. That is, sync and async commands cannot be +// reordered. The only difference between a sync and async command is that +// the return value is ignored in the async case, but they are executed in +// the same way, and the same order, on the main thread. void emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIGNATURE sig, void *func_ptr, ...); // The 'async_waitable' variant of the run_in_main_runtime_thread functions run From 494b4e6aabf16bf27890685f21ae3ad917619a90 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 10 Nov 2020 09:42:54 -0800 Subject: [PATCH 2/2] feedback --- system/include/emscripten/threading.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/system/include/emscripten/threading.h b/system/include/emscripten/threading.h index f26f3ed09d976..fee6348f64733 100644 --- a/system/include/emscripten/threading.h +++ b/system/include/emscripten/threading.h @@ -311,10 +311,13 @@ int emscripten_sync_run_in_main_runtime_thread_(EM_FUNC_SIGNATURE sig, void *fun // guaranteed to be executed on the main thread in the program order they // were called in. // - Note that synchronous and asynchronous commands are *also* guaranteed to -// be executed in order. That is, sync and async commands cannot be -// reordered. The only difference between a sync and async command is that -// the return value is ignored in the async case, but they are executed in -// the same way, and the same order, on the main thread. +// be executed in order. That is, all commands, sync and async, will not get +// reordered in the queue, but will be executed in the sequential order in +// which they were dispatched. If you issue commands A, B, C, then regardless +// of which of them are sync or async, they will execute in that same order +// on the main runtime thread. The only difference between an async and a +// sync command is that an async one has no return value, and does not block +// the calling thread. void emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIGNATURE sig, void *func_ptr, ...); // The 'async_waitable' variant of the run_in_main_runtime_thread functions run