changeset 10628:b40075443afa

Use msvcrt aware primitives for creation/termination of Win32 threads.
author Bruno Haible <bruno@clisp.org>
date Sun, 12 Oct 2008 15:13:06 +0200
parents 04756a28484d
children fc3e861affff 591ae6a784d9
files ChangeLog lib/glthread/thread.c
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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>
 
--- a/lib/glthread/thread.c
+++ b/lib/glthread/thread.c
@@ -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 @@
 
 /* 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 @@
   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_t thread = gl_thread_self ();
   thread->result = retval;
-  ExitThread (0);
+  _endthreadex (0); /* calls ExitThread (0) */
 }
 
 #endif