Skip to content

Commit c84ebdc

Browse files
committed
Fix deadlock in test_pthread_run_on_main_thread
Fixes: emscripten-core#18210
1 parent fdc2ea7 commit c84ebdc

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

test/pthread/test_pthread_run_on_main_thread.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,65 @@
1111
int v_called = 0;
1212
void v() {
1313
assert(emscripten_is_main_runtime_thread());
14-
printf("Hello!\n");
14+
emscripten_outf("Hello!");
1515
v_called = 1;
1616
}
1717

1818
int vi_called = 0;
1919
void vi(int param0) {
2020
assert(emscripten_is_main_runtime_thread());
21-
printf("Hello %d!\n", param0);
21+
emscripten_outf("Hello %d!", param0);
2222
vi_called = 1;
2323
}
2424

2525
int vii_called = 0;
2626
void vii(int param0, int param1) {
2727
assert(emscripten_is_main_runtime_thread());
28-
printf("Hello %d %d!\n", param0, param1);
28+
emscripten_outf("Hello %d %d!", param0, param1);
2929
vii_called = 1;
3030
}
3131

3232
int viii_called = 0;
3333
void viii(int param0, int param1, int param2) {
3434
assert(emscripten_is_main_runtime_thread());
35-
printf("Hello %d %d %d!\n", param0, param1, param2);
35+
emscripten_outf("Hello %d %d %d!", param0, param1, param2);
3636
viii_called = 1;
3737
}
3838

3939
int i_called = 0;
4040
int i() {
4141
assert(emscripten_is_main_runtime_thread());
42-
printf("Hello i!\n");
42+
emscripten_outf("Hello i!");
4343
i_called = 1;
4444
return 84;
4545
}
4646

4747
int ii_called = 0;
4848
int ii(int param0) {
4949
assert(emscripten_is_main_runtime_thread());
50-
printf("Hello ii %d!\n", param0);
50+
emscripten_outf("Hello ii %d!", param0);
5151
ii_called = 1;
5252
return 85;
5353
}
5454

5555
int iii_called = 0;
5656
int iii(int param0, int param1) {
5757
assert(emscripten_is_main_runtime_thread());
58-
printf("Hello iii %d %d!\n", param0, param1);
58+
emscripten_outf("Hello iii %d %d!", param0, param1);
5959
iii_called = 1;
6060
return 86;
6161
}
6262

6363
int iiii_called = 0;
6464
int iiii(int param0, int param1, int param2) {
6565
assert(emscripten_is_main_runtime_thread());
66-
printf("Hello iiii %d %d %d!\n", param0, param1, param2);
66+
emscripten_outf("Hello iiii %d %d %d!", param0, param1, param2);
6767
iiii_called = 1;
6868
return 87;
6969
}
7070

7171
void test_sync() {
72-
printf("Testing sync proxied runs:\n");
72+
emscripten_outf("Testing sync proxied runs:");
7373
int ret;
7474
v_called = 0; emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_V, v); assert(v_called == 1);
7575
vi_called = 0; emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42); assert(vi_called == 1);
@@ -82,7 +82,7 @@ void test_sync() {
8282
}
8383

8484
void test_async() {
85-
printf("Testing async proxied runs:\n");
85+
emscripten_outf("Testing async proxied runs:");
8686
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
8787
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42);
8888
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VII, vii, 42, 43);
@@ -94,7 +94,7 @@ void test_async() {
9494
}
9595

9696
void test_async_waitable() {
97-
printf("Testing waitable async proxied runs:\n");
97+
emscripten_outf("Testing waitable async proxied runs:");
9898
em_queued_call *c1 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
9999
em_queued_call *c2 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42);
100100
em_queued_call *c3 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_VII, vii, 42, 43);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Testing sync proxied runs:
2+
Hello!
3+
Hello 42!
4+
Hello 42 43!
5+
Hello 42 43 44!
6+
Hello i!
7+
Hello ii 42!
8+
Hello iii 42 43!
9+
Hello iiii 42 43 44!
10+
Testing waitable async proxied runs:
11+
Hello!
12+
Hello 42!
13+
Hello 42 43!
14+
Hello 42 43 44!
15+
Hello i!
16+
Hello ii 42!
17+
Hello iii 42 43!
18+
Hello iiii 42 43 44!
19+
Testing sync proxied runs:
20+
Hello!
21+
Hello 42!
22+
Hello 42 43!
23+
Hello 42 43 44!
24+
Hello i!
25+
Hello ii 42!
26+
Hello iii 42 43!
27+
Hello iiii 42 43 44!
28+
Testing async proxied runs:
29+
Testing waitable async proxied runs:
30+
Hello!
31+
Hello 42!
32+
Hello 42 43!
33+
Hello 42 43 44!
34+
Hello i!
35+
Hello ii 42!
36+
Hello iii 42 43!
37+
Hello iiii 42 43 44!
38+
Hello!
39+
Hello 42!
40+
Hello 42 43!
41+
Hello 42 43 44!
42+
Hello i!
43+
Hello ii 42!
44+
Hello iii 42 43!
45+
Hello iiii 42 43 44!
46+
Testing async proxied runs:
47+
Hello!
48+
Hello 42!
49+
Hello 42 43!
50+
Hello 42 43 44!
51+
Hello i!
52+
Hello ii 42!
53+
Hello iii 42 43!
54+
Hello iiii 42 43 44!

test/test_browser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4249,7 +4249,6 @@ def test_pthread_gauge_available_memory(self, args):
42494249

42504250
# Test that the proxying operations of user code from pthreads to main thread
42514251
# work
4252-
@disabled('https://github.com/emscripten-core/emscripten/issues/18210')
42534252
@requires_threads
42544253
def test_pthread_run_on_main_thread(self):
42554254
self.btest_exit('pthread/test_pthread_run_on_main_thread.c', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE'])

test/test_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,10 @@ def test_pthread_wait_async(self):
26392639
self.set_setting('PROXY_TO_PTHREAD')
26402640
self.do_run_in_out_file_test('atomic/test_wait_async.c')
26412641

2642+
@node_pthreads
2643+
def test_pthread_run_on_main_thread(self):
2644+
self.do_run_in_out_file_test('pthread/test_pthread_run_on_main_thread.c')
2645+
26422646
def test_tcgetattr(self):
26432647
self.do_runf('termios/test_tcgetattr.c', 'success')
26442648

0 commit comments

Comments
 (0)