Skip to content

Commit d1d1147

Browse files
authored
Cleanup pthread tests. NFC. (#13211)
1 parent 8e885f7 commit d1d1147

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

system/include/emscripten/threading.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,21 +393,21 @@ void emscripten_thread_sleep(double msecs);
393393
// Sets the profiler status of the calling thread. This is a no-op if thread
394394
// profiling is not active.
395395
// This is an internal function and generally not intended for user code.
396-
// When thread profiler is not enabled (not building with --threadprofiling),
396+
// When thread profiler is not enabled (not building with --threadprofiler),
397397
// this is a no-op.
398398
void emscripten_set_current_thread_status(EM_THREAD_STATUS newStatus);
399399

400400
// Sets the profiler status of the calling thread, but only if it was in the
401401
// expected status beforehand.
402402
// This is an internal function and generally not intended for user code.
403-
// When thread profiler is not enabled (not building with --threadprofiling),
403+
// When thread profiler is not enabled (not building with --threadprofiler),
404404
// this is a no-op.
405405
void emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS expectedStatus, EM_THREAD_STATUS newStatus);
406406

407407
// Sets the name of the given thread. Pass pthread_self() as the thread ID to
408408
// set the name of the calling thread.
409409
// The name parameter is a UTF-8 encoded string which is truncated to 32 bytes.
410-
// When thread profiler is not enabled (not building with --threadprofiling),
410+
// When thread profiler is not enabled (not building with --threadprofiler),
411411
// this is a no-op.
412412
void emscripten_set_thread_name(pthread_t threadId, const char *name);
413413

system/lib/libc/musl/src/internal/pthread_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct pthread {
2222
// by direct pointer arithmetic in worker.js.
2323
int threadStatus; // 0: thread not exited, 1: exited.
2424
int threadExitCode; // Thread exit code.
25-
void *profilerBlock; // If --threadprofiling is enabled, this pointer is allocated to contain internal information about the thread state for profiling purposes.
25+
void *profilerBlock; // If --threadprofiler is enabled, this pointer is allocated to contain internal information about the thread state for profiling purposes.
2626
#endif
2727

2828
struct pthread *self;

tests/core/pthread/create.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ static std::atomic<int> sum;
1818

1919
void *ThreadMain(void *arg) {
2020
for (int i = 0; i < TOTAL; i++) {
21-
sum++;
2221
// wait for a change, so we see interleaved processing.
23-
int last = sum.load();
22+
int last = ++sum;
2423
while (sum.load() == last) {}
2524
}
2625
pthread_exit((void*)TOTAL);
@@ -30,24 +29,20 @@ pthread_t thread[NUM_THREADS];
3029

3130
void CreateThread(int i)
3231
{
33-
static int counter = 1;
3432
int rc = pthread_create(&thread[i], nullptr, ThreadMain, (void*)i);
3533
assert(rc == 0);
3634
}
3735

3836
void mainn() {
3937
static int main_adds = 0;
40-
int worker_adds = sum.load() - main_adds;
41-
sum++;
42-
main_adds++;
38+
int worker_adds = sum++ - main_adds++;
4339
printf("main iter %d : %d\n", main_adds, worker_adds);
4440
if (worker_adds == NUM_THREADS * TOTAL) {
4541
printf("done!\n");
4642
#ifndef ALLOW_SYNC
47-
emscripten_cancel_main_loop();
48-
#else
49-
exit(0);
43+
emscripten_cancel_main_loop();
5044
#endif
45+
exit(0);
5146
}
5247
}
5348

@@ -64,4 +59,5 @@ int main() {
6459
#else
6560
while (1) mainn();
6661
#endif
62+
return 0;
6763
}

tests/core/pthread/exceptions.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ void *ThreadMain(void *arg) {
3131
} catch (int x) {
3232
total += x;
3333
} catch (float f) {
34-
sum++;
3534
// wait for a change, so we see interleaved processing.
36-
int last = sum.load();
35+
int last = ++sum;
3736
while (sum.load() == last) {}
3837
}
3938
}
@@ -50,9 +49,7 @@ void CreateThread(int i)
5049

5150
void loop() {
5251
static int main_adds = 0;
53-
int worker_adds = sum.load() - main_adds;
54-
sum++;
55-
main_adds++;
52+
int worker_adds = sum++ - main_adds++;
5653
printf("main iter %d : %d\n", main_adds, worker_adds);
5754
if (worker_adds == NUM_THREADS * THREAD_ADDS &&
5855
main_adds >= MAIN_ADDS) {
@@ -65,9 +62,10 @@ void loop() {
6562
int main() {
6663
// Create initial threads.
6764
for(int i = 0; i < NUM_THREADS; ++i) {
68-
printf("maek\n");
65+
printf("make\n");
6966
CreateThread(i);
7067
}
7168

7269
emscripten_set_main_loop(loop, 0, 0);
70+
return 0;
7371
}

tests/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8069,6 +8069,7 @@ def test_fpic_static(self):
80698069

80708070
@node_pthreads
80718071
def test_pthread_create(self):
8072+
self.set_setting('EXIT_RUNTIME')
80728073
self.do_run_in_out_file_test('tests', 'core', 'pthread', 'create.cpp')
80738074

80748075
@node_pthreads

0 commit comments

Comments
 (0)