Skip to content

Commit 09d8052

Browse files
authored
Remove uncessary use of PTHREAD_CREATE_JOINABLE in test code. NFC. (#12404)
Threads are joinable by default, there is no need to set this attribute.
1 parent 72ae069 commit 09d8052

18 files changed

+15
-64
lines changed

system/lib/pthread/library_pthread.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,6 @@ int proxy_main(int argc, char** argv) {
938938
if (emscripten_has_threading_support()) {
939939
pthread_attr_t attr;
940940
pthread_attr_init(&attr);
941-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
942941
// Use TOTAL_STACK for the stack size, which is the normal size of the stack
943942
// that main() would have without PROXY_TO_PTHREAD.
944943
pthread_attr_setstacksize(&attr, EM_ASM_INT({ return TOTAL_STACK }));

tests/core/pthread/create.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ pthread_t thread[NUM_THREADS];
3030

3131
void CreateThread(int i)
3232
{
33-
pthread_attr_t attr;
34-
pthread_attr_init(&attr);
35-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
3633
static int counter = 1;
37-
int rc = pthread_create(&thread[i], &attr, ThreadMain, (void*)i);
34+
int rc = pthread_create(&thread[i], nullptr, ThreadMain, (void*)i);
3835
assert(rc == 0);
39-
pthread_attr_destroy(&attr);
4036
}
4137

4238
void mainn() {

tests/gl_in_pthread.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ void CreateThread()
6767
pthread_attr_t attr;
6868
pthread_attr_init(&attr);
6969
emscripten_pthread_attr_settransferredcanvases(&attr, "#canvas");
70-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
7170
int rc = pthread_create(&thread, &attr, ThreadMain, 0);
7271
if (rc == ENOSYS)
7372
{

tests/gl_in_two_pthreads.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void run_thread(int param)
5151
pthread_attr_t attr;
5252
pthread_attr_init(&attr);
5353
emscripten_pthread_attr_settransferredcanvases(&attr, "#canvas");
54-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
5554
pthread_t thread;
5655
int rc = pthread_create(&thread, &attr, thread_main, (void*)param);
5756
assert(rc == 0);

tests/pthread/test_pthread_64bit_atomics.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ void RunTest(int test)
9191
{
9292
pthread_attr_t attr;
9393
pthread_attr_init(&attr);
94-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
9594
pthread_attr_setstacksize(&attr, 4*1024);
9695

9796
printf("Main thread has thread ID %d\n", (int)pthread_self());

tests/pthread/test_pthread_atomics.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void RunTest(int test)
103103
{
104104
pthread_attr_t attr;
105105
pthread_attr_init(&attr);
106-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
107106
pthread_attr_setstacksize(&attr, 4*1024);
108107

109108
printf("Main thread has thread ID %d\n", (int)pthread_self());

tests/pthread/test_pthread_attr_getstack.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ int main()
5252
}
5353

5454
pthread_t thread;
55-
pthread_attr_t attr;
5655
int rc, result;
5756

58-
pthread_attr_init(&attr);
59-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
60-
rc = pthread_create(&thread, &attr, ThreadMain, NULL);
57+
rc = pthread_create(&thread, NULL, ThreadMain, NULL);
6158
assert(rc == 0);
62-
pthread_attr_destroy(&attr);
6359

6460
rc = pthread_join(thread, (void**)&result);
6561
assert(rc == 0);

tests/pthread/test_pthread_condition_variable.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,15 @@ int main (int argc, char *argv[])
8080
int i, rc;
8181
long t1=1, t2=2, t3=3;
8282
pthread_t threads[3];
83-
pthread_attr_t attr;
8483

8584
/* Initialize mutex and condition variable objects */
8685
pthread_mutex_init(&count_mutex, NULL);
8786
pthread_cond_init (&count_threshold_cv, NULL);
8887

8988
/* For portability, explicitly create threads in a joinable state */
90-
pthread_attr_init(&attr);
91-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
92-
pthread_create(&threads[0], &attr, watch_count, (void *)t1);
93-
pthread_create(&threads[1], &attr, inc_count, (void *)t2);
94-
pthread_create(&threads[2], &attr, inc_count, (void *)t3);
89+
pthread_create(&threads[0], NULL, watch_count, (void *)t1);
90+
pthread_create(&threads[1], NULL, inc_count, (void *)t2);
91+
pthread_create(&threads[2], NULL, inc_count, (void *)t3);
9592

9693
if (emscripten_has_threading_support())
9794
{
@@ -103,7 +100,6 @@ int main (int argc, char *argv[])
103100
}
104101

105102
/* Clean up and exit */
106-
pthread_attr_destroy(&attr);
107103
pthread_mutex_destroy(&count_mutex);
108104
pthread_cond_destroy(&count_threshold_cv);
109105
#ifdef REPORT_RESULT

tests/pthread/test_pthread_create.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,11 @@ int numThreadsToCreate = 1000;
6161

6262
void CreateThread(int i)
6363
{
64-
pthread_attr_t attr;
65-
pthread_attr_init(&attr);
66-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
6764
static int counter = 1;
6865
global_shared_data[i] = (counter++ * 12141231) & 0x7FFFFFFF; // Arbitrary random'ish data for perturbing the sort for this thread task.
6966
// EM_ASM(out('Main: Creating thread idx ' + $0 + ' (param ' + $1 + ')'), i, global_shared_data[i]);
70-
int rc = pthread_create(&thread[i], &attr, ThreadMain, (void*)i);
67+
int rc = pthread_create(&thread[i], NULL, ThreadMain, (void*)i);
7168
assert(rc == 0);
72-
pthread_attr_destroy(&attr);
7369
}
7470

7571
int main()

tests/pthread/test_pthread_gcc_spinlock.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ int main()
6060

6161
for(int i = 0; i < NUM_THREADS; ++i)
6262
{
63-
pthread_attr_t attr;
64-
pthread_attr_init(&attr);
65-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
66-
int rc = pthread_create(&thread[i], &attr, ThreadMain, 0);
63+
int rc = pthread_create(&thread[i], NULL, ThreadMain, 0);
6764
if (rc != 0 || thread[i] == 0)
6865
printf("Failed to create thread!\n");
69-
pthread_attr_destroy(&attr);
7066
}
7167

7268
for(int i = 0; i < NUM_THREADS; ++i)

tests/pthread/test_pthread_hardware_concurrency.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void RunTest(int test)
3636

3737
pthread_attr_t attr;
3838
pthread_attr_init(&attr);
39-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
4039
pthread_attr_setstacksize(&attr, 4*1024);
4140

4241
printf("Main thread has thread ID %d\n", (int)pthread_self());

tests/pthread/test_pthread_mandelbrot.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,8 @@ int main(int argc, char** argv)
585585
maxThreadsRunning = emscripten_num_logical_cores() < MAX_NUM_THREADS ? emscripten_num_logical_cores() : MAX_NUM_THREADS;
586586
for(int i = 0; i < maxThreadsRunning; ++i)
587587
{
588-
pthread_attr_t attr;
589-
pthread_attr_init(&attr);
590-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
591-
int rc = pthread_create(&thread[i], &attr, mandelbrot_thread, (void*)i);
588+
int rc = pthread_create(&thread[i], NULL, mandelbrot_thread, (void*)i);
592589
assert(rc == 0);
593-
pthread_attr_destroy(&attr);
594590
}
595591
#endif
596592

tests/pthread/test_pthread_mutex.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ void CreateThread(int i, int n)
4747
{
4848
pthread_attr_t attr;
4949
pthread_attr_init(&attr);
50-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
5150
pthread_attr_setstacksize(&attr, 4*1024);
5251
int rc = pthread_create(&thread[i], &attr, ThreadMain, 0);
5352
if (rc != 0 || thread[i] == 0)

tests/pthread/test_pthread_proxying_in_futex_wait.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ int main()
4242
}
4343

4444
pthread_t thread;
45-
pthread_attr_t attr;
46-
pthread_attr_init(&attr);
47-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
48-
int rc = pthread_create(&thread, &attr, ThreadMain, 0);
45+
int rc = pthread_create(&thread, NULL, ThreadMain, 0);
4946
assert(rc == 0);
5047
rc = emscripten_futex_wait(&main_thread_wait_val, 1, 15 * 1000);
5148
// An rc of 0 means no error, and of EWOULDBLOCK means that the value is
@@ -60,7 +57,6 @@ int main()
6057
#endif
6158
exit(1);
6259
}
63-
pthread_attr_destroy(&attr);
6460
pthread_join(thread, 0);
6561

6662
#ifdef REPORT_RESULT

tests/pthread/test_pthread_run_on_main_thread.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@ int main()
147147
test_sync();
148148
test_async_waitable();
149149

150-
pthread_attr_t attr;
151-
pthread_attr_init(&attr);
152-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
153150
pthread_t thread;
154-
int rc = pthread_create(&thread, &attr, thread_main, 0);
151+
int rc = pthread_create(&thread, NULL, thread_main, NULL);
155152
assert(rc == 0);
156153
rc = pthread_join(thread, 0);
157154
assert(rc == 0);

tests/pthread/test_pthread_run_on_main_thread_flood.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ int main()
7171
test_sync();
7272
test_async_waitable();
7373

74-
pthread_attr_t attr;
75-
pthread_attr_init(&attr);
76-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
7774
pthread_t thread;
78-
int rc = pthread_create(&thread, &attr, thread_main, 0);
75+
int rc = pthread_create(&thread, NULL, thread_main, NULL);
7976
assert(rc == 0);
8077
rc = pthread_join(thread, 0);
8178
assert(rc == 0);

tests/pthread/test_pthread_supported.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313

1414
void *ThreadMain(void *arg)
1515
{
16-
pthread_exit(0);
16+
pthread_exit(NULL);
1717
}
1818

1919
int main()
2020
{
2121
pthread_t thread;
22-
pthread_attr_t attr;
23-
pthread_attr_init(&attr);
24-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
25-
int rc = pthread_create(&thread, &attr, ThreadMain, 0);
26-
pthread_attr_destroy(&attr);
27-
pthread_join(thread, 0);
22+
int rc = pthread_create(&thread, NULL, ThreadMain, NULL);
23+
pthread_join(thread, NULL);
2824

2925
if (emscripten_has_threading_support()) assert(rc == 0);
3026
else assert(rc == EAGAIN);

tests/pthread/test_pthread_thread_local_storage.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ int numThreadsToCreate = 32;
5151

5252
void CreateThread(int i)
5353
{
54-
pthread_attr_t attr;
55-
pthread_attr_init(&attr);
56-
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
57-
int rc = pthread_create(&thread[i], &attr, ThreadMain, (void*)i);
54+
int rc = pthread_create(&thread[i], NULL, ThreadMain, (void*)i);
5855
if (emscripten_has_threading_support()) assert(rc == 0);
5956
else assert(rc == EAGAIN);
60-
pthread_attr_destroy(&attr);
6157
}
6258

6359
int main()

0 commit comments

Comments
 (0)