Skip to content

Commit 05ea93f

Browse files
committed
Fix race condition in browser.test_audioworklet_worker where worker might miss the wakeup signal that audio worklet has posted.
1 parent 361ebd7 commit 05ea93f

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

test/webaudio/audioworklet_worker.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <emscripten/threading.h>
44
#include <assert.h>
55
#include <stdbool.h>
6+
#include <errno.h>
67

78
// Tests that
89
// - audioworklets and workers can be used at the same time.
@@ -21,13 +22,11 @@ void do_exit() {
2122
void run_in_worker() {
2223
double start = emscripten_performance_now();
2324
emscripten_outf("run_in_worker");
24-
while (emscripten_futex_wait(&workletToWorkerFlag, 0, 30000) == 0) {
25-
if (workletToWorkerFlag == true) {
26-
emscripten_outf("Test success (waited %.fms)", emscripten_performance_now() - start);
27-
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, &do_exit);
28-
break;
29-
}
25+
while (emscripten_futex_wait(&workletToWorkerFlag, 0, 30000) == -ETIMEDOUT) {
26+
emscripten_outf("worker wait timed out, repeating wait..");
3027
}
28+
emscripten_outf("Test success (waited %.fms)", emscripten_performance_now() - start);
29+
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, &do_exit);
3130
}
3231

3332
// This event will fire on the audio worklet thread.

0 commit comments

Comments
 (0)