Skip to content

Commit 018f836

Browse files
Christopher Friedtcfriedt
authored andcommitted
posix: pthread: consider PTHREAD_EXITED state in pthread_create
If a thread is joined using `pthread_join()`, then the internal state would be set to `PTHREAD_EXITED`. Previously, `pthread_create()` would only consider pthreads with internal state `PTHREAD_TERMINATED` as candidates for new threads. However, that causes a descriptor leak. We should be able to reuse a single thread an infinite number of times. Here, we also consider threads with internal state `PTHREAD_EXITED` as candiates in `pthread_create()`. Fixes #47609 Signed-off-by: Christopher Friedt <[email protected]> (cherry picked from commit da0398d)
1 parent f4466c4 commit 018f836

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/posix/pthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
150150
for (pthread_num = 0;
151151
pthread_num < CONFIG_MAX_PTHREAD_COUNT; pthread_num++) {
152152
thread = &posix_thread_pool[pthread_num];
153-
if (thread->state == PTHREAD_TERMINATED) {
153+
if (thread->state == PTHREAD_EXITED || thread->state == PTHREAD_TERMINATED) {
154154
thread->state = PTHREAD_JOINABLE;
155155
break;
156156
}

0 commit comments

Comments
 (0)