Skip to content

Commit 0941ca2

Browse files
authored
Fix flakiness in test_pthread_nested_work_queue. NFC (#15188)
Given the right timing the thread could start and finish all before the work item was scheduled. We have seen this test flake in this way a few times recently.
1 parent e36ffaf commit 0941ca2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/pthread/test_pthread_nested_work_queue.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#include <stdio.h>
2+
#include <stdbool.h>
3+
#include <stdatomic.h>
24
#include <emscripten/threading.h>
35
#include <emscripten/emscripten.h>
46

7+
atomic_bool work_done = false;
8+
59
void work() {
610
// This `work` item is called from within
711
// `emscripten_current_thread_process_queued_calls`.
812
// Calling `emscripten_thread_sleep` here will trigger another nested call to
913
// `emscripten_current_thread_process_queued_calls`.
1014
printf("Begin work\n");
1115
emscripten_thread_sleep(1);
16+
work_done = true;
1217
printf("End work\n");
1318
}
1419

1520
void* thread_func(void* _param) {
1621
printf("Start thread\n");
17-
emscripten_thread_sleep(1);
22+
while (!work_done) {
23+
emscripten_thread_sleep(1);
24+
}
1825
printf("End thread\n");
1926
return NULL;
2027
};

0 commit comments

Comments
 (0)