diff mbox series

[v11,2/2] win32: close handles of threads that have been joined

Message ID c5d2ddad166165d1ac8975ce6d06c16eb3b6b6cb.1671823177.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series win32: close handles of threads that have been joined | expand

Commit Message

Seija Kijin Dec. 23, 2022, 7:19 p.m. UTC
From: Seija Kijin <doremylover123@gmail.com>

After the thread terminates, the handle to the
original thread should be closed.

This change makes win32_pthread_join POSIX compliant.

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
 compat/win32/pthread.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

René Scharfe Dec. 24, 2022, 7:50 a.m. UTC | #1
Am 23.12.22 um 20:19 schrieb Seija Kijin via GitGitGadget:
> From: Seija Kijin <doremylover123@gmail.com>
>
> After the thread terminates, the handle to the
> original thread should be closed.
>
> This change makes win32_pthread_join POSIX compliant.
>
> Signed-off-by: Seija Kijin <doremylover123@gmail.com>
> ---
>  compat/win32/pthread.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c
> index 65e15a560d5..f63f65c9dfe 100644
> --- a/compat/win32/pthread.c
> +++ b/compat/win32/pthread.c
> @@ -41,11 +41,15 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
>  	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:
> -		return err_win_to_posix(GetLastError());
> +		/* the wait failed, so do not detach */
> +		errno = err_win_to_posix(GetLastError());
> +		return errno;

Why do we need to set errno?  That's the only difference to v10, but I
didn't find an explanation.  POSIX only mentions the return value:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html

>  	}
>  }
>
diff mbox series

Patch

diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c
index 65e15a560d5..f63f65c9dfe 100644
--- a/compat/win32/pthread.c
+++ b/compat/win32/pthread.c
@@ -41,11 +41,15 @@  int win32_pthread_join(pthread_t *thread, void **value_ptr)
 	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:
-		return err_win_to_posix(GetLastError());
+		/* the wait failed, so do not detach */
+		errno = err_win_to_posix(GetLastError());
+		return errno;
 	}
 }