diff --git a/test/pthread/main_thread_join.cpp b/test/pthread/main_thread_join.c similarity index 90% rename from test/pthread/main_thread_join.cpp rename to test/pthread/main_thread_join.c index ece9c74d59920..a3d7841c62ac5 100644 --- a/test/pthread/main_thread_join.cpp +++ b/test/pthread/main_thread_join.c @@ -8,11 +8,9 @@ #include #include -#include - pthread_t thread; -std::atomic tries; +_Atomic int tries; static const int EXPECTED_TRIES = 7; @@ -21,7 +19,7 @@ void loop() { printf("try...\n"); if (pthread_tryjoin_np(thread, &retval) == 0) { emscripten_cancel_main_loop(); - assert(tries.load() == EXPECTED_TRIES); + assert(tries == EXPECTED_TRIES); emscripten_force_exit(2); } tries++; @@ -31,7 +29,7 @@ void *ThreadMain(void *arg) { #ifdef TRY_JOIN // Delay to force the main thread to try and fail a few times before // succeeding. - while (tries.load() < EXPECTED_TRIES) {} + while (tries < EXPECTED_TRIES) {} #endif pthread_exit((void*)0); } diff --git a/test/pthread/test_pthread_barrier.cpp b/test/pthread/test_pthread_barrier.c similarity index 100% rename from test/pthread/test_pthread_barrier.cpp rename to test/pthread/test_pthread_barrier.c diff --git a/test/pthread/test_pthread_condition_variable.cpp b/test/pthread/test_pthread_condition_variable.c similarity index 100% rename from test/pthread/test_pthread_condition_variable.cpp rename to test/pthread/test_pthread_condition_variable.c diff --git a/test/pthread/test_pthread_proxying_in_futex_wait.cpp b/test/pthread/test_pthread_proxying_in_futex_wait.c similarity index 100% rename from test/pthread/test_pthread_proxying_in_futex_wait.cpp rename to test/pthread/test_pthread_proxying_in_futex_wait.c diff --git a/test/pthread/test_pthread_spawns.cpp b/test/pthread/test_pthread_spawns.c similarity index 100% rename from test/pthread/test_pthread_spawns.cpp rename to test/pthread/test_pthread_spawns.c diff --git a/test/pthread/test_pthread_stack_bounds.cpp b/test/pthread/test_pthread_stack_bounds.c similarity index 71% rename from test/pthread/test_pthread_stack_bounds.cpp rename to test/pthread/test_pthread_stack_bounds.c index 9bb5420f18ffd..676ca59039eb8 100644 --- a/test/pthread/test_pthread_stack_bounds.cpp +++ b/test/pthread/test_pthread_stack_bounds.c @@ -1,20 +1,22 @@ -#include -#include +#include +#include #include #include -void thread(void) { +void* thread_main(void* arg) { bool passed; size_t stack_base = emscripten_stack_get_base(); size_t stack_max = emscripten_stack_get_end(); size_t current = (size_t) &passed; assert(stack_base > current && current > stack_max); emscripten_force_exit(0); + return 0; } +pthread_t t; + int main(void) { - std::thread t(thread); - t.detach(); + pthread_create(&t, NULL, thread_main, NULL); emscripten_exit_with_live_runtime(); __builtin_trap(); } diff --git a/test/pthread/test_pthread_thread_local_storage.cpp b/test/pthread/test_pthread_thread_local_storage.c similarity index 100% rename from test/pthread/test_pthread_thread_local_storage.cpp rename to test/pthread/test_pthread_thread_local_storage.c diff --git a/test/pthread/test_pthread_tls_main.cpp b/test/pthread/test_pthread_tls_main.c similarity index 77% rename from test/pthread/test_pthread_tls_main.cpp rename to test/pthread/test_pthread_tls_main.c index bbf873c52ce18..dfc3754254183 100644 --- a/test/pthread/test_pthread_tls_main.cpp +++ b/test/pthread/test_pthread_tls_main.c @@ -1,6 +1,5 @@ -#include -#include -#include +#include +#include thread_local int tls = 1330; thread_local int tls2; diff --git a/test/test_browser.py b/test/test_browser.py index d4b960c451fdd..bf935ec74a483 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -3708,15 +3708,16 @@ def test_pthread_main_thread_blocking_join(self): }; ''') # Test that we warn about blocking on the main thread in debug builds - self.btest('pthread/main_thread_join.cpp', expected='got_warn', cflags=['-sEXIT_RUNTIME', '-sASSERTIONS', '--pre-js', 'pre.js', '-pthread', '-sPTHREAD_POOL_SIZE']) + self.cflags.append('-D_GNU_SOURCE') # For pthread_tryjoin_np + self.btest('pthread/main_thread_join.c', expected='got_warn', cflags=['-sEXIT_RUNTIME', '-sASSERTIONS', '--pre-js', 'pre.js', '-pthread', '-sPTHREAD_POOL_SIZE']) # Test that we do not warn about blocking on the main thread in release builds - self.btest_exit('pthread/main_thread_join.cpp', cflags=['-O3', '--pre-js', 'pre.js', '-pthread', '-sPTHREAD_POOL_SIZE']) + self.btest_exit('pthread/main_thread_join.c', cflags=['-O3', '--pre-js', 'pre.js', '-pthread', '-sPTHREAD_POOL_SIZE']) # Test that tryjoin is fine, even if not ALLOW_BLOCKING_ON_MAIN_THREAD - self.btest_exit('pthread/main_thread_join.cpp', assert_returncode=2, cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE', '-g', '-DTRY_JOIN', '-sALLOW_BLOCKING_ON_MAIN_THREAD=0']) + self.btest_exit('pthread/main_thread_join.c', assert_returncode=2, cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE', '-g', '-DTRY_JOIN', '-sALLOW_BLOCKING_ON_MAIN_THREAD=0']) # Test that tryjoin is fine, even if not ALLOW_BLOCKING_ON_MAIN_THREAD, and even without a pool - self.btest_exit('pthread/main_thread_join.cpp', assert_returncode=2, cflags=['-O3', '-pthread', '-g', '-DTRY_JOIN', '-sALLOW_BLOCKING_ON_MAIN_THREAD=0']) + self.btest_exit('pthread/main_thread_join.c', assert_returncode=2, cflags=['-O3', '-pthread', '-g', '-DTRY_JOIN', '-sALLOW_BLOCKING_ON_MAIN_THREAD=0']) # Test that everything works ok when we are on a pthread - self.btest_exit('pthread/main_thread_join.cpp', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE', '-sPROXY_TO_PTHREAD', '-sALLOW_BLOCKING_ON_MAIN_THREAD=0']) + self.btest_exit('pthread/main_thread_join.c', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE', '-sPROXY_TO_PTHREAD', '-sALLOW_BLOCKING_ON_MAIN_THREAD=0']) # Test the old GCC atomic __sync_fetch_and_op builtin operations. @parameterized({ @@ -3855,7 +3856,7 @@ def test_pthread_malloc_free(self): # Test that the pthread_barrier API works ok. def test_pthread_barrier(self): - self.btest_exit('pthread/test_pthread_barrier.cpp', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8']) + self.btest_exit('pthread/test_pthread_barrier.c', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8']) # Test the pthread_once() function. def test_pthread_once(self): @@ -3863,7 +3864,7 @@ def test_pthread_once(self): # Test against a certain thread exit time handling bug by spawning tons of threads. def test_pthread_spawns(self): - self.btest_exit('pthread/test_pthread_spawns.cpp', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8', '--closure=1', '-sENVIRONMENT=web']) + self.btest_exit('pthread/test_pthread_spawns.c', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8', '--closure=1', '-sENVIRONMENT=web']) # It is common for code to flip volatile global vars for thread control. This is a bit lax, but nevertheless, test whether that # kind of scheme will work with Emscripten as well. @@ -3876,11 +3877,11 @@ def test_pthread_volatile(self, args): # Test thread-specific data (TLS). def test_pthread_thread_local_storage(self): - self.btest_exit('pthread/test_pthread_thread_local_storage.cpp', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8', '-sASSERTIONS']) + self.btest_exit('pthread/test_pthread_thread_local_storage.c', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8', '-sASSERTIONS']) # Test the pthread condition variable creation and waiting. def test_pthread_condition_variable(self): - self.btest_exit('pthread/test_pthread_condition_variable.cpp', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8']) + self.btest_exit('pthread/test_pthread_condition_variable.c', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8']) # Test that pthreads are able to do printf. @parameterized({ @@ -3910,7 +3911,7 @@ def test_pthread_file_io(self): # Test that the pthread_create() function operates benignly in the case that threading is not supported. @parameterized({ '': ([],), - 'mt': (['-pthread', '-sPTHREAD_POOL_SIZE=8'],), + 'mt': (['-pthread', '-sPTHREAD_POOL_SIZE=1'],), }) def test_pthread_supported(self, args): self.btest_exit('pthread/test_pthread_supported.c', cflags=['-O3'] + args) @@ -3922,7 +3923,7 @@ def test_pthread_dispatch_after_exit(self): # needs it to do a proxied operation (before that pthread would wake up the # main thread), that it's not a deadlock. def test_pthread_proxying_in_futex_wait(self): - self.btest_exit('pthread/test_pthread_proxying_in_futex_wait.cpp', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE']) + self.btest_exit('pthread/test_pthread_proxying_in_futex_wait.c', cflags=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE']) # Test that sbrk() operates properly in multithreaded conditions @no_2gb('uses INITIAL_MEMORY') @@ -4004,7 +4005,7 @@ def test_pthread_wake_all(self): # Test that stack base and max correctly bound the stack on pthreads. def test_pthread_stack_bounds(self): - self.btest_exit('pthread/test_pthread_stack_bounds.cpp', cflags=['-pthread']) + self.btest_exit('pthread/test_pthread_stack_bounds.c', cflags=['-pthread']) # Test that real `thread_local` works. def test_pthread_tls(self): @@ -4012,7 +4013,7 @@ def test_pthread_tls(self): # Test that real `thread_local` works in main thread without PROXY_TO_PTHREAD. def test_pthread_tls_main(self): - self.btest_exit('pthread/test_pthread_tls_main.cpp', cflags=['-pthread']) + self.btest_exit('pthread/test_pthread_tls_main.c', cflags=['-pthread']) def test_pthread_safe_stack(self): # Note that as the test runs with PROXY_TO_PTHREAD, we set STACK_SIZE, diff --git a/test/test_core.py b/test/test_core.py index 7d52e6fdd3831..36a48ba9928fa 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -2651,7 +2651,7 @@ def test_pthread_thread_local_storage(self): self.set_setting('EXIT_RUNTIME') if not self.has_changed_setting('INITIAL_MEMORY'): self.set_setting('INITIAL_MEMORY', '300mb') - self.do_run_in_out_file_test('pthread/test_pthread_thread_local_storage.cpp') + self.do_run_in_out_file_test('pthread/test_pthread_thread_local_storage.c') @requires_pthreads def test_pthread_cleanup(self):