diff --git a/emcc.py b/emcc.py index 3d86609924a56..4d30b2f04984b 100755 --- a/emcc.py +++ b/emcc.py @@ -2117,7 +2117,7 @@ def compile_source_file(i, input_file): if not shared.Settings.SIDE_MODULE: # shared libraries/side modules link no C libraries, need them in parent extra_files_to_link = system_libs.get_ports(shared.Settings) if '-nostdlib' not in newargs and '-nodefaultlibs' not in newargs: - link_as_cxx = run_via_emxx + link_as_cxx = run_via_emxx or shared.Settings.EMBIND # Traditionally we always link as C++. For compatibility we continue to do that, # unless running in strict mode. if not shared.Settings.STRICT and '-nostdlib++' not in newargs: diff --git a/tests/core/pthread/create.cpp b/tests/core/pthread/create.c similarity index 72% rename from tests/core/pthread/create.cpp rename to tests/core/pthread/create.c index 5608dc8ea7145..7b35ecade0d99 100644 --- a/tests/core/pthread/create.cpp +++ b/tests/core/pthread/create.c @@ -3,25 +3,25 @@ // 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++) { sum++; // wait for a change, so we see interleaved processing. - int last = sum.load(); - while (sum.load() == last) {} + int last = sum; + while (sum == last) {} } pthread_exit((void*)TOTAL); } @@ -30,38 +30,39 @@ pthread_t thread[NUM_THREADS]; void CreateThread(int i) { - static int counter = 1; - int rc = pthread_create(&thread[i], nullptr, ThreadMain, (void*)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.load() - main_adds; + int worker_adds = sum - main_adds; sum++; main_adds++; printf("main iter %d : %d\n", main_adds, worker_adds); if (worker_adds == NUM_THREADS * TOTAL) { printf("done!\n"); #ifndef ALLOW_SYNC - emscripten_cancel_main_loop(); + emscripten_cancel_main_loop(); #else - exit(0); + exit(0); #endif } } int main() { // Create initial threads. - for(int i = 0; i < NUM_THREADS; ++i) { + for (int i = 0; i < NUM_THREADS; ++i) { CreateThread(i); } // 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 } diff --git a/tests/test_core.py b/tests/test_core.py index 7909bad4285a3..24b69dbbb7ba5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -8097,28 +8097,28 @@ def test_fpic_static(self): @node_pthreads def test_pthread_create(self): - self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.cpp') + self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.c') @node_pthreads def test_pthread_create_pool(self): # with a pool, we can synchronously depend on workers being available self.set_setting('PTHREAD_POOL_SIZE', '2') self.emcc_args += ['-DALLOW_SYNC'] - self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.cpp') + self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.c') @node_pthreads def test_pthread_create_proxy(self): # with PROXY_TO_PTHREAD, we can synchronously depend on workers being available self.set_setting('PROXY_TO_PTHREAD', '1') self.emcc_args += ['-DALLOW_SYNC'] - self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.cpp') + self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.c') @node_pthreads def test_pthread_create_embind_stack_check(self): # embind should work with stack overflow checks (see #12356) self.set_setting('STACK_OVERFLOW_CHECK', 2) self.emcc_args += ['--bind'] - self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.cpp') + self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.c') @node_pthreads def test_pthread_exceptions(self): @@ -8129,13 +8129,11 @@ def test_pthread_exceptions(self): def test_emscripten_atomics_stub(self): self.do_run_in_out_file_test('tests', 'core', 'pthread', 'emscripten_atomics.c') - @no_asan('incompatibility with atomics') @node_pthreads def test_emscripten_atomics(self): self.set_setting('USE_PTHREADS', '1') self.do_run_in_out_file_test('tests', 'core', 'pthread', 'emscripten_atomics.c') - @no_asan('incompatibility with atomics') @node_pthreads def test_emscripten_futexes(self): self.set_setting('USE_PTHREADS', '1')