[PATCH v6 1/2] win32: close handles of threads that have been joined
- From
- Seija Kijin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Dec 21, 2022, 04:35 UTC
- Message-ID
- <0b5afdb93dbf20e8467368be77779b89201a0cad.1671597317.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1406.v6.git.git.1671597317.gitgitgadget@gmail.com>
From: Seija Kijin <doremylover123@gmail.com>
After joining threads, the handle to the original thread should be closed as it no longer needs to be open.
This change makes the function POSIX compliant.
Signed-off-by: Seija Kijin <doremylover123@gmail.com> --- compat/win32/pthread.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c index 2e7eead42cb..cf94b4491f9 100644 --- a/compat/win32/pthread.c +++ b/compat/win32/pthread.c @@ -37,16 +37,18 @@ int pthread_create(pthread_t *thread, const void *unused, int win32_pthread_join(pthread_t *thread, void **value_ptr) { - DWORD result = WaitForSingleObject(thread->handle, INFINITE); - switch (result) { - case WAIT_OBJECT_0: - if (value_ptr) - *value_ptr = thread->arg; - return 0; - case WAIT_ABANDONED: - return EINVAL; - default: - return err_win_to_posix(GetLastError()); + switch (WaitForSingleObject(thread->handle, INFINITE)) { + case WAIT_OBJECT_0: + if (value_ptr) + *value_ptr = thread->arg; + CloseHandle(thread->handle); + return 0; + case WAIT_ABANDONED: + CloseHandle(thread->handle); + return EINVAL; + default: + /* the function failed, so do not detach */ + return err_win_to_posix(GetLastError()); } }
-- gitgitgadget