Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/pthread/test_pthread_print_seq_consistent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2025 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <pthread.h>
#include <emscripten/console.h>

void *pthread_main(void *arg) {
emscripten_out("thread has started.");
return 0;
}

int main() {
pthread_t t;
pthread_create(&t, 0, pthread_main, 0);
pthread_join(t, 0);
emscripten_out("thread joined");
}
3 changes: 3 additions & 0 deletions test/pthread/test_pthread_print_seq_consistent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (!ENVIRONMENT_IS_PTHREAD) {
Module.print = (text) => { console.log(text); }
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file needed? Shouldn't we be testing the default behaviour of emscripten_out

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see your are testing both.

What happens if you override Module.print on the pthreads too? i.e. is the if condition import here? I would hope not, since calls out should be proxied back to the main threads's print handler regardless.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the if condition import here?

Yes, it is important.

I would hope not, since calls out should be proxied back to the main threads's print handler regardless.

No, that is not correct. If pthread overrides a print handler, then it is not proxied to the main thread.

if (!Module[handler] || Module[handler].proxy) {

2 changes: 2 additions & 0 deletions test/pthread/test_pthread_print_seq_consistent.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
thread has started.
thread joined
11 changes: 11 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,17 @@ def test_pthread_run_on_main_thread(self):
self.skipTest('MINIMAL_RUNTIME + threads + asan does not work')
self.do_run_in_out_file_test('pthread/test_pthread_run_on_main_thread.c')

# This test verifies that printing from a pthread has sequential consistency.
@node_pthreads
@parameterized({
'': ([],),
'print_override': (['--pre-js', test_file('pthread/test_pthread_print_seq_consistent.js')],),
})
def test_pthread_print_seq_consistent(self, cflags):
self.skipTest('Currently broken due to https://github.com/emscripten-core/emscripten/issues/19683')
self.do_run_in_out_file_test('pthread/test_pthread_print_seq_consistent.c',
cflags=cflags)

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

Expand Down