Commit f4ad7994 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Win32: do not assume the thread is joined before it exits

parent f18192c6
...@@ -527,19 +527,30 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data, ...@@ -527,19 +527,30 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
if (hThread) if (hThread)
{ {
/* Thread closes the handle when exiting, duplicate it here
* to be on the safe side when joining. */
if (!DuplicateHandle (GetCurrentProcess (), hThread,
GetCurrentProcess (), &th->handle, 0, FALSE,
DUPLICATE_SAME_ACCESS))
{
CloseHandle (hThread);
free (th);
return ENOMEM;
}
ResumeThread (hThread); ResumeThread (hThread);
th->handle = hThread; th->handle = hThread;
if (priority) if (priority)
SetThreadPriority (hThread, priority); SetThreadPriority (hThread, priority);
ret = 0; ret = 0;
*p_handle = th;
} }
else else
{ {
ret = errno; ret = errno;
free (th); free (th);
th = NULL;
} }
*p_handle = th;
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
*p_handle = spawn_thread( entry, psz_name, priority, data ); *p_handle = spawn_thread( entry, psz_name, priority, data );
...@@ -561,19 +572,8 @@ int vlc_join (vlc_thread_t handle, void **result) ...@@ -561,19 +572,8 @@ int vlc_join (vlc_thread_t handle, void **result)
return pthread_join (handle, result); return pthread_join (handle, result);
#elif defined( UNDER_CE ) || defined( WIN32 ) #elif defined( UNDER_CE ) || defined( WIN32 )
HANDLE hThread; WaitForSingleObject (handle->handle, INFINITE);
CloseHandle (handle->handle);
/*
** object will close its thread handle when destroyed, duplicate it here
** to be on the safe side
*/
if (!DuplicateHandle (GetCurrentProcess (), handle->handle,
GetCurrentProcess(), &hThread, 0, FALSE,
DUPLICATE_SAME_ACCESS))
return GetLastError (); /* FIXME: errno */
WaitForSingleObject (hThread, INFINITE);
CloseHandle (hThread);
if (result) if (result)
*result = handle->data; *result = handle->data;
free (handle); free (handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment