Merge branch 'sk/win32-close-handle-upon-pthread-join'

Pthread emulation on Win32 leaked thread handle when a thread is
joined.

* sk/win32-close-handle-upon-pthread-join:
  win32: close handles of threads that have been joined
  win32: prepare pthread.c for change by formatting
maint
Junio C Hamano 2023-01-23 13:39:51 -08:00
commit 6e0f966efe
1 changed files with 14 additions and 11 deletions

View File

@ -26,8 +26,8 @@ int pthread_create(pthread_t *thread, const void *unused,
{ {
thread->arg = arg; thread->arg = arg;
thread->start_routine = start_routine; thread->start_routine = start_routine;
thread->handle = (HANDLE) thread->handle = (HANDLE)_beginthreadex(NULL, 0, win32_start_routine,
_beginthreadex(NULL, 0, win32_start_routine, thread, 0, NULL); thread, 0, NULL);


if (!thread->handle) if (!thread->handle)
return errno; return errno;
@ -42,10 +42,13 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
if (value_ptr) if (value_ptr)
*value_ptr = thread->arg; *value_ptr = thread->arg;
CloseHandle(thread->handle);
return 0; return 0;
case WAIT_ABANDONED: case WAIT_ABANDONED:
CloseHandle(thread->handle);
return EINVAL; return EINVAL;
default: default:
/* the wait failed, so do not detach */
return err_win_to_posix(GetLastError()); return err_win_to_posix(GetLastError());
} }
} }