Skip to content

Commit 9da7880

Browse files
committed
Fix deadlock in test_pthread_run_on_main_thread
Fixes: emscripten-core#18210
1 parent 7bba399 commit 9da7880

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

test/pthread/test_pthread_run_on_main_thread.cpp

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

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

2727
int vii_called = 0;
2828
void vii(int param0, int param1)
2929
{
3030
assert(emscripten_is_main_runtime_thread());
31-
printf("Hello %d %d!\n", param0, param1);
31+
emscripten_outf("Hello %d %d!", param0, param1);
3232
vii_called = 1;
3333
}
3434

3535
int viii_called = 0;
3636
void viii(int param0, int param1, int param2)
3737
{
3838
assert(emscripten_is_main_runtime_thread());
39-
printf("Hello %d %d %d!\n", param0, param1, param2);
39+
emscripten_outf("Hello %d %d %d!", param0, param1, param2);
4040
viii_called = 1;
4141
}
4242

4343
int i_called = 0;
4444
int i()
4545
{
4646
assert(emscripten_is_main_runtime_thread());
47-
printf("Hello i!\n");
47+
emscripten_outf("Hello i!");
4848
i_called = 1;
4949
return 84;
5050
}
@@ -53,7 +53,7 @@ int ii_called = 0;
5353
int ii(int param0)
5454
{
5555
assert(emscripten_is_main_runtime_thread());
56-
printf("Hello ii %d!\n", param0);
56+
emscripten_outf("Hello ii %d!", param0);
5757
ii_called = 1;
5858
return 85;
5959
}
@@ -62,7 +62,7 @@ int iii_called = 0;
6262
int iii(int param0, int param1)
6363
{
6464
assert(emscripten_is_main_runtime_thread());
65-
printf("Hello iii %d %d!\n", param0, param1);
65+
emscripten_outf("Hello iii %d %d!", param0, param1);
6666
iii_called = 1;
6767
return 86;
6868
}
@@ -71,14 +71,14 @@ int iiii_called = 0;
7171
int iiii(int param0, int param1, int param2)
7272
{
7373
assert(emscripten_is_main_runtime_thread());
74-
printf("Hello iiii %d %d %d!\n", param0, param1, param2);
74+
emscripten_outf("Hello iiii %d %d %d!", param0, param1, param2);
7575
iiii_called = 1;
7676
return 87;
7777
}
7878

7979
void test_sync()
8080
{
81-
printf("Testing sync proxied runs:\n");
81+
emscripten_outf("Testing sync proxied runs:");
8282
int ret;
8383
v_called = 0; emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_V, v); assert(v_called == 1);
8484
vi_called = 0; emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42); assert(vi_called == 1);
@@ -92,7 +92,7 @@ void test_sync()
9292

9393
void test_async()
9494
{
95-
printf("Testing async proxied runs:\n");
95+
emscripten_outf("Testing async proxied runs:");
9696
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
9797
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42);
9898
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VII, vii, 42, 43);
@@ -105,7 +105,7 @@ void test_async()
105105

106106
void test_async_waitable()
107107
{
108-
printf("Testing waitable async proxied runs:\n");
108+
emscripten_outf("Testing waitable async proxied runs:");
109109
em_queued_call *c1 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
110110
em_queued_call *c2 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42);
111111
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
@@ -4246,7 +4246,6 @@ def test_pthread_gauge_available_memory(self, args):
42464246

42474247
# Test that the proxying operations of user code from pthreads to main thread
42484248
# work
4249-
@disabled('https://github.com/emscripten-core/emscripten/issues/18210')
42504249
@requires_threads
42514250
def test_pthread_run_on_main_thread(self):
42524251
self.btest_exit('pthread/test_pthread_run_on_main_thread.cpp', 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.cpp')
2645+
26422646
def test_tcgetattr(self):
26432647
self.do_runf('termios/test_tcgetattr.c', 'success')
26442648

0 commit comments

Comments
 (0)