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 <cfriedt@fb.com>
(cherry picked from commit da0398d198)
This commit is contained in:
Christopher Friedt 2022-07-11 07:09:04 -04:00 committed by Christopher Friedt
parent f4466c4760
commit 018f836c4d
1 changed files with 1 additions and 1 deletions

View File

@ -150,7 +150,7 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
for (pthread_num = 0;
pthread_num < CONFIG_MAX_PTHREAD_COUNT; pthread_num++) {
thread = &posix_thread_pool[pthread_num];
if (thread->state == PTHREAD_TERMINATED) {
if (thread->state == PTHREAD_EXITED || thread->state == PTHREAD_TERMINATED) {
thread->state = PTHREAD_JOINABLE;
break;
}