Skip to content

Commit 09d8052

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

18 files changed

Lines changed: 15 additions & 64 deletions

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)

0 commit comments

Comments
 (0)