Skip to content

Commit e4b05eb

Browse files
committed
Wait for returner to start up
1 parent 54ae773 commit e4b05eb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/pthread/test_pthread_proxying.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ pthread_t returner;
1717

1818
// The queue used to send work to both `looper` and `returner`.
1919
em_proxying_queue* proxy_queue = NULL;
20+
21+
// Whether `looper` should exit.
2022
_Atomic int should_quit = 0;
2123

24+
// Whether `returner` has spun up.
25+
_Atomic int has_begun = 0;
26+
2227
void* looper_main(void* arg) {
2328
while (!should_quit) {
2429
emscripten_proxy_execute_queue(proxy_queue);
@@ -27,7 +32,10 @@ void* looper_main(void* arg) {
2732
return NULL;
2833
}
2934

30-
void* returner_main(void* arg) { emscripten_exit_with_live_runtime(); }
35+
void* returner_main(void* arg) {
36+
has_begun = 1;
37+
emscripten_exit_with_live_runtime();
38+
}
3139

3240
typedef struct widget {
3341
// `val` will be stored to `out` and the current thread will be stored to
@@ -322,6 +330,11 @@ int main(int argc, char* argv[]) {
322330
pthread_create(&looper, NULL, looper_main, NULL);
323331
pthread_create(&returner, NULL, returner_main, NULL);
324332

333+
// `returner` can't process its queue until it starts up.
334+
while (!has_begun) {
335+
sched_yield();
336+
}
337+
325338
test_proxy_async();
326339
test_proxy_sync();
327340
test_proxy_sync_with_ctx();

0 commit comments

Comments
 (0)