From 3c4ceee3aa06d592df21860967e54a42f02793ad Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 10 Nov 2020 11:45:02 -0800 Subject: [PATCH] Cleanup test/core/pthread/create. NFC. Mostly convert to C to match the other tests here. See #3494 --- test/core/pthread/{create.cpp => create.c} | 19 ++++++++++--------- test/test_core.py | 8 ++++---- 2 files changed, 14 insertions(+), 13 deletions(-) rename test/core/pthread/{create.cpp => create.c} (81%) diff --git a/test/core/pthread/create.cpp b/test/core/pthread/create.c similarity index 81% rename from test/core/pthread/create.cpp rename to test/core/pthread/create.c index dd07d5c585899..65041b0066c02 100644 --- a/test/core/pthread/create.cpp +++ b/test/core/pthread/create.c @@ -3,37 +3,36 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. +#include #include #include #include #include #include -#include #define NUM_THREADS 2 #define TOTAL 100 -static std::atomic sum; +static _Atomic int sum; void *ThreadMain(void *arg) { for (int i = 0; i < TOTAL; i++) { // wait for a change, so we see interleaved processing. int last = ++sum; - while (sum.load() == last) {} + while (sum == last) {} } pthread_exit((void*)TOTAL); } pthread_t thread[NUM_THREADS]; -void CreateThread(long i) -{ - int rc = pthread_create(&thread[i], nullptr, ThreadMain, (void*)i); +void CreateThread(long i) { + int rc = pthread_create(&thread[i], NULL, ThreadMain, (void*)i); assert(rc == 0); } -void mainn() { +void main_iter() { static int main_adds = 0; int worker_adds = sum++ - main_adds++; printf("main iter %d : %d\n", main_adds, worker_adds); @@ -55,9 +54,11 @@ int main() { // if we don't allow sync pthread creation, the event loop must be reached for // the worker to start up. #ifndef ALLOW_SYNC - emscripten_set_main_loop(mainn, 0, 0); + emscripten_set_main_loop(main_iter, 0, 0); #else - while (1) mainn(); + while (1) { + main_iter(); + } #endif return 0; } diff --git a/test/test_core.py b/test/test_core.py index cb6f09d17f014..78924afb29bce 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -9102,7 +9102,7 @@ def test_pthread_create(self): # works with pthreads (even though we did not specify 'node,worker') self.set_setting('ENVIRONMENT', 'node') self.set_setting('STRICT_JS') - self.do_run_in_out_file_test('core/pthread/create.cpp') + self.do_run_in_out_file_test('core/pthread/create.c') @node_pthreads @parameterized({ @@ -9149,7 +9149,7 @@ def test_pthread_create_pool(self): self.set_setting('PTHREAD_POOL_SIZE', 2) self.set_setting('EXIT_RUNTIME') self.emcc_args += ['-DALLOW_SYNC'] - self.do_run_in_out_file_test('core/pthread/create.cpp') + self.do_run_in_out_file_test('core/pthread/create.c') @node_pthreads def test_pthread_create_proxy(self): @@ -9157,7 +9157,7 @@ def test_pthread_create_proxy(self): self.set_setting('PROXY_TO_PTHREAD') self.set_setting('EXIT_RUNTIME') self.emcc_args += ['-DALLOW_SYNC'] - self.do_run_in_out_file_test('core/pthread/create.cpp') + self.do_run_in_out_file_test('core/pthread/create.c') @node_pthreads def test_pthread_create_embind_stack_check(self): @@ -9165,7 +9165,7 @@ def test_pthread_create_embind_stack_check(self): self.set_setting('STACK_OVERFLOW_CHECK', 2) self.set_setting('EXIT_RUNTIME') self.emcc_args += ['-lembind'] - self.do_run_in_out_file_test('core/pthread/create.cpp') + self.do_run_in_out_file_test('core/pthread/create.c', emcc_args=['-sDEFAULT_TO_CXX']) @node_pthreads def test_pthread_exceptions(self):