-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix Wasm Workers calling emscripten_futex_wait() when building with pthreads support enabled. Fixes #21549. #21618
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Test that emscripten_futex_wait() works in a Wasm Worker. | ||
|
|
||
| #include <emscripten.h> | ||
| #include <emscripten/console.h> | ||
| #include <emscripten/threading.h> | ||
| #include <emscripten/wasm_worker.h> | ||
| #include <limits.h> | ||
| #include <stdio.h> | ||
| #include <math.h> | ||
|
|
||
| _Atomic uint32_t futex_value = 0; | ||
|
|
||
| void wake_worker_after_delay(void *user_data) { | ||
| futex_value = 1; | ||
| emscripten_futex_wake(&futex_value, INT_MAX); | ||
| } | ||
|
|
||
| void wake_worker() { | ||
| printf("Waking worker thread from futex wait.\n"); | ||
| emscripten_set_timeout(wake_worker_after_delay, 500, 0); | ||
| } | ||
|
|
||
| void worker_main() { | ||
| printf("Worker sleeping for futex wait.\n"); | ||
| emscripten_wasm_worker_post_function_v(0, wake_worker); | ||
| int rc = emscripten_futex_wait(&futex_value, 0, INFINITY); | ||
| printf("emscripten_futex_wait returned with code %d.\n", rc); | ||
| #ifdef REPORT_RESULT | ||
| REPORT_RESULT(rc); | ||
| #endif | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got ReferenceError: document not defined |
||
| } | ||
|
|
||
| int main() { | ||
| emscripten_wasm_worker_post_function_v(emscripten_malloc_wasm_worker(1024), worker_main); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if an AudioWorklet ends up calling
emscripten_futex_wait, it looks like it will just unconditionally fail/trap when it calls __builtin_wasm_memory_atomic_wait32 on line 158 ofemscripten_futex_wait.c. Is that just expected to not work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will then abort in the newly added assert(). That'll be work for a separate PR.