Use msvcrt aware primitives for creation/termination of Win32 threads.
authorBruno Haible <bruno@clisp.org>
Sun, 12 Oct 2008 13:13:06 +0000 (15:13 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 12 Oct 2008 13:13:06 +0000 (15:13 +0200)
ChangeLog
lib/glthread/thread.c

index dd1b73d..9723875 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-12  Bruno Haible  <bruno@clisp.org>
+
+       Use msvcrt aware primitives for creation/termination of Win32 threads.
+       * lib/glthread/thread.c: Include <process.h>.
+       (glthread_create_func): Use _beginthreadex instead of CreateThread.
+       (wrapper_func): Update signature.
+       (gl_thread_exit_func): Use _endthreadex instead of EndThread.
+
 2008-10-11  Yoann Vandoorselaere  <yoann@prelude-ids.org>
             Bruno Haible  <bruno@clisp.org>
 
index 521b68c..4ebfc54 100644 (file)
@@ -31,6 +31,8 @@
 
 #if USE_WIN32_THREADS
 
+#include <process.h>
+
 /* -------------------------- gl_thread_t datatype -------------------------- */
 
 /* The Thread-Local Storage (TLS) key that allows to access each thread's
@@ -118,7 +120,7 @@ gl_thread_self_func (void)
 
 /* The main function of a freshly creating thread.  It's a wrapper around
    the FUNC and ARG arguments passed to glthread_create_func.  */
-static DWORD WINAPI
+static unsigned int WINAPI
 wrapper_func (void *varg)
 {
   struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
@@ -154,11 +156,12 @@ glthread_create_func (gl_thread_t *threadp, void * (*func) (void *), void *arg)
   thread->arg = arg;
 
   {
-    DWORD thread_id;
+    unsigned int thread_id;
     HANDLE thread_handle;
 
-    thread_handle =
-      CreateThread (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+    thread_handle = (HANDLE)
+      _beginthreadex (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+      /* calls CreateThread with the same arguments */
     if (thread_handle == NULL)
       {
        DeleteCriticalSection (&thread->handle_lock);
@@ -206,7 +209,7 @@ gl_thread_exit_func (void *retval)
 {
   gl_thread_t thread = gl_thread_self ();
   thread->result = retval;
-  ExitThread (0);
+  _endthreadex (0); /* calls ExitThread (0) */
 }
 
 #endif