Skip to content

Commit

Permalink
Fix deadlock in test_pthread_run_on_main_thread
Browse files Browse the repository at this point in the history
Fixes: #18210
  • Loading branch information
sbc100 committed Feb 8, 2024
1 parent fdc2ea7 commit c84ebdc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
22 changes: 11 additions & 11 deletions test/pthread/test_pthread_run_on_main_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,65 @@
int v_called = 0;
void v() {
assert(emscripten_is_main_runtime_thread());
printf("Hello!\n");
emscripten_outf("Hello!");
v_called = 1;
}

int vi_called = 0;
void vi(int param0) {
assert(emscripten_is_main_runtime_thread());
printf("Hello %d!\n", param0);
emscripten_outf("Hello %d!", param0);
vi_called = 1;
}

int vii_called = 0;
void vii(int param0, int param1) {
assert(emscripten_is_main_runtime_thread());
printf("Hello %d %d!\n", param0, param1);
emscripten_outf("Hello %d %d!", param0, param1);
vii_called = 1;
}

int viii_called = 0;
void viii(int param0, int param1, int param2) {
assert(emscripten_is_main_runtime_thread());
printf("Hello %d %d %d!\n", param0, param1, param2);
emscripten_outf("Hello %d %d %d!", param0, param1, param2);
viii_called = 1;
}

int i_called = 0;
int i() {
assert(emscripten_is_main_runtime_thread());
printf("Hello i!\n");
emscripten_outf("Hello i!");
i_called = 1;
return 84;
}

int ii_called = 0;
int ii(int param0) {
assert(emscripten_is_main_runtime_thread());
printf("Hello ii %d!\n", param0);
emscripten_outf("Hello ii %d!", param0);
ii_called = 1;
return 85;
}

int iii_called = 0;
int iii(int param0, int param1) {
assert(emscripten_is_main_runtime_thread());
printf("Hello iii %d %d!\n", param0, param1);
emscripten_outf("Hello iii %d %d!", param0, param1);
iii_called = 1;
return 86;
}

int iiii_called = 0;
int iiii(int param0, int param1, int param2) {
assert(emscripten_is_main_runtime_thread());
printf("Hello iiii %d %d %d!\n", param0, param1, param2);
emscripten_outf("Hello iiii %d %d %d!", param0, param1, param2);
iiii_called = 1;
return 87;
}

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

void test_async() {
printf("Testing async proxied runs:\n");
emscripten_outf("Testing async proxied runs:");
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42);
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VII, vii, 42, 43);
Expand All @@ -94,7 +94,7 @@ void test_async() {
}

void test_async_waitable() {
printf("Testing waitable async proxied runs:\n");
emscripten_outf("Testing waitable async proxied runs:");
em_queued_call *c1 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
em_queued_call *c2 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_VI, vi, 42);
em_queued_call *c3 = emscripten_async_waitable_run_in_main_runtime_thread(EM_FUNC_SIG_VII, vii, 42, 43);
Expand Down
54 changes: 54 additions & 0 deletions test/pthread/test_pthread_run_on_main_thread.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Testing sync proxied runs:
Hello!
Hello 42!
Hello 42 43!
Hello 42 43 44!
Hello i!
Hello ii 42!
Hello iii 42 43!
Hello iiii 42 43 44!
Testing waitable async proxied runs:
Hello!
Hello 42!
Hello 42 43!
Hello 42 43 44!
Hello i!
Hello ii 42!
Hello iii 42 43!
Hello iiii 42 43 44!
Testing sync proxied runs:
Hello!
Hello 42!
Hello 42 43!
Hello 42 43 44!
Hello i!
Hello ii 42!
Hello iii 42 43!
Hello iiii 42 43 44!
Testing async proxied runs:
Testing waitable async proxied runs:
Hello!
Hello 42!
Hello 42 43!
Hello 42 43 44!
Hello i!
Hello ii 42!
Hello iii 42 43!
Hello iiii 42 43 44!
Hello!
Hello 42!
Hello 42 43!
Hello 42 43 44!
Hello i!
Hello ii 42!
Hello iii 42 43!
Hello iiii 42 43 44!
Testing async proxied runs:
Hello!
Hello 42!
Hello 42 43!
Hello 42 43 44!
Hello i!
Hello ii 42!
Hello iii 42 43!
Hello iiii 42 43 44!
1 change: 0 additions & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4249,7 +4249,6 @@ def test_pthread_gauge_available_memory(self, args):

# Test that the proxying operations of user code from pthreads to main thread
# work
@disabled('https://github.com/emscripten-core/emscripten/issues/18210')
@requires_threads
def test_pthread_run_on_main_thread(self):
self.btest_exit('pthread/test_pthread_run_on_main_thread.c', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE'])
Expand Down
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,10 @@ def test_pthread_wait_async(self):
self.set_setting('PROXY_TO_PTHREAD')
self.do_run_in_out_file_test('atomic/test_wait_async.c')

@node_pthreads
def test_pthread_run_on_main_thread(self):
self.do_run_in_out_file_test('pthread/test_pthread_run_on_main_thread.c')

def test_tcgetattr(self):
self.do_runf('termios/test_tcgetattr.c', 'success')

Expand Down

0 comments on commit c84ebdc

Please sign in to comment.