Skip to content

Commit c00356e

Browse files
authored
Cleanup test/core/pthread/create. NFC. (#12756)
Mostly convert to C to match the other tests here. See #3494
1 parent fa47840 commit c00356e

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

test/core/pthread/create.cpp renamed to test/core/pthread/create.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6+
#include <stdatomic.h>
67
#include <stdio.h>
78
#include <stdlib.h>
89
#include <pthread.h>
910
#include <assert.h>
1011
#include <emscripten.h>
1112

12-
#include <atomic>
1313

1414
#define NUM_THREADS 2
1515
#define TOTAL 100
1616

17-
static std::atomic<int> sum;
17+
static _Atomic int sum;
1818

1919
void *ThreadMain(void *arg) {
2020
for (int i = 0; i < TOTAL; i++) {
2121
// wait for a change, so we see interleaved processing.
2222
int last = ++sum;
23-
while (sum.load() == last) {}
23+
while (sum == last) {}
2424
}
2525
pthread_exit((void*)TOTAL);
2626
}
2727

2828
pthread_t thread[NUM_THREADS];
2929

30-
void CreateThread(long i)
31-
{
32-
int rc = pthread_create(&thread[i], nullptr, ThreadMain, (void*)i);
30+
void CreateThread(long i) {
31+
int rc = pthread_create(&thread[i], NULL, ThreadMain, (void*)i);
3332
assert(rc == 0);
3433
}
3534

36-
void mainn() {
35+
void main_iter() {
3736
static int main_adds = 0;
3837
int worker_adds = sum++ - main_adds++;
3938
printf("main iter %d : %d\n", main_adds, worker_adds);
@@ -55,9 +54,11 @@ int main() {
5554
// if we don't allow sync pthread creation, the event loop must be reached for
5655
// the worker to start up.
5756
#ifndef ALLOW_SYNC
58-
emscripten_set_main_loop(mainn, 0, 0);
57+
emscripten_set_main_loop(main_iter, 0, 0);
5958
#else
60-
while (1) mainn();
59+
while (1) {
60+
main_iter();
61+
}
6162
#endif
6263
return 0;
6364
}

test/test_core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9102,7 +9102,7 @@ def test_pthread_create(self):
91029102
# works with pthreads (even though we did not specify 'node,worker')
91039103
self.set_setting('ENVIRONMENT', 'node')
91049104
self.set_setting('STRICT_JS')
9105-
self.do_run_in_out_file_test('core/pthread/create.cpp')
9105+
self.do_run_in_out_file_test('core/pthread/create.c')
91069106

91079107
@node_pthreads
91089108
@parameterized({
@@ -9149,23 +9149,23 @@ def test_pthread_create_pool(self):
91499149
self.set_setting('PTHREAD_POOL_SIZE', 2)
91509150
self.set_setting('EXIT_RUNTIME')
91519151
self.emcc_args += ['-DALLOW_SYNC']
9152-
self.do_run_in_out_file_test('core/pthread/create.cpp')
9152+
self.do_run_in_out_file_test('core/pthread/create.c')
91539153

91549154
@node_pthreads
91559155
def test_pthread_create_proxy(self):
91569156
# with PROXY_TO_PTHREAD, we can synchronously depend on workers being available
91579157
self.set_setting('PROXY_TO_PTHREAD')
91589158
self.set_setting('EXIT_RUNTIME')
91599159
self.emcc_args += ['-DALLOW_SYNC']
9160-
self.do_run_in_out_file_test('core/pthread/create.cpp')
9160+
self.do_run_in_out_file_test('core/pthread/create.c')
91619161

91629162
@node_pthreads
91639163
def test_pthread_create_embind_stack_check(self):
91649164
# embind should work with stack overflow checks (see #12356)
91659165
self.set_setting('STACK_OVERFLOW_CHECK', 2)
91669166
self.set_setting('EXIT_RUNTIME')
91679167
self.emcc_args += ['-lembind']
9168-
self.do_run_in_out_file_test('core/pthread/create.cpp')
9168+
self.do_run_in_out_file_test('core/pthread/create.c', emcc_args=['-sDEFAULT_TO_CXX'])
91699169

91709170
@node_pthreads
91719171
def test_pthread_exceptions(self):

0 commit comments

Comments
 (0)