-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wasm workers under node (#22721)
- Use callUserCallback to invoke callback in _wasmWorkerRunPostMessage. Without this calls to exit/emscripten_force_exit within the callback don't work as expected (they cause unhandled exception errors). - Fix `onmessage` handling under node so that the message payload always arrives as the `data` member of the message. - Update a few of the wasm workers tests do they actually exit (required for running tests under node).
- Loading branch information
Showing
8 changed files
with
67 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
#include <emscripten/emscripten.h> | ||
#include <emscripten/console.h> | ||
#include <emscripten/em_asm.h> | ||
#include <emscripten/wasm_worker.h> | ||
#include <assert.h> | ||
|
||
// This is the code example in site/source/docs/api_reference/wasm_workers.rst | ||
void do_exit() { | ||
emscripten_out("do_exit"); | ||
emscripten_terminate_all_wasm_workers(); | ||
emscripten_force_exit(0); | ||
} | ||
|
||
void run_in_worker() { | ||
emscripten_out("Hello from wasm worker!\n"); | ||
EM_ASM(typeof checkStackCookie == 'function' && checkStackCookie()); | ||
#ifdef REPORT_RESULT | ||
REPORT_RESULT(0); | ||
#endif | ||
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); | ||
} | ||
|
||
int main() { | ||
emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(/*stack size: */1024); | ||
assert(worker); | ||
emscripten_wasm_worker_post_function_v(worker, run_in_worker); | ||
emscripten_exit_with_live_runtime(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters