[vlc-devel] commit: Win32: do not assume the thread is joined before it exits ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Aug 27 19:25:57 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Wed Aug 27 20:28:47 2008 +0300| [f4ad7994761cd2463ad15254aa5569a444484c7c] | committer: Rémi Denis-Courmont 

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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f4ad7994761cd2463ad15254aa5569a444484c7c
---

 src/misc/threads.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/misc/threads.c b/src/misc/threads.c
index 656babc..2f221dd 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -527,19 +527,30 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
 
     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);
         th->handle = hThread;
         if (priority)
             SetThreadPriority (hThread, priority);
+
         ret = 0;
+        *p_handle = th;
     }
     else
     {
         ret = errno;
         free (th);
-        th = NULL;
     }
-    *p_handle = th;
 
 #elif defined( HAVE_KERNEL_SCHEDULER_H )
     *p_handle = spawn_thread( entry, psz_name, priority, data );
@@ -561,19 +572,8 @@ int vlc_join (vlc_thread_t handle, void **result)
     return pthread_join (handle, result);
 
 #elif defined( UNDER_CE ) || defined( WIN32 )
-    HANDLE hThread;
-
-    /*
-    ** 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);
+    WaitForSingleObject (handle->handle, INFINITE);
+    CloseHandle (handle->handle);
     if (result)
         *result = handle->data;
     free (handle);




More information about the vlc-devel mailing list