bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

thread.c win32 tweak


From: Bruno Haible
Subject: thread.c win32 tweak
Date: Sun, 12 Oct 2008 15:16:42 +0200
User-agent: KMail/1.5.4

On mingw, it's probably better to use the MSVCRT primitives for thread
creation and termination, rather than the Win32 API ones. They provide
an exception handler for C++ style exceptions in the created thread.


2008-10-12  Bruno Haible  <address@hidden>

        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.

*** lib/glthread/thread.c.orig  2008-10-12 15:09:49.000000000 +0200
--- lib/glthread/thread.c       2008-10-12 15:08:10.000000000 +0200
***************
*** 31,36 ****
--- 31,38 ----
  
  #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,124 ****
  
  /* 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
  wrapper_func (void *varg)
  {
    struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
--- 120,126 ----
  
  /* The main function of a freshly creating thread.  It's a wrapper around
     the FUNC and ARG arguments passed to glthread_create_func.  */
! static unsigned int WINAPI
  wrapper_func (void *varg)
  {
    struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
***************
*** 154,164 ****
    thread->arg = arg;
  
    {
!     DWORD thread_id;
      HANDLE thread_handle;
  
!     thread_handle =
!       CreateThread (NULL, 100000, wrapper_func, thread, 0, &thread_id);
      if (thread_handle == NULL)
        {
        DeleteCriticalSection (&thread->handle_lock);
--- 156,167 ----
    thread->arg = arg;
  
    {
!     unsigned int thread_id;
      HANDLE thread_handle;
  
!     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,212 ****
  {
    gl_thread_t thread = gl_thread_self ();
    thread->result = retval;
!   ExitThread (0);
  }
  
  #endif
--- 209,215 ----
  {
    gl_thread_t thread = gl_thread_self ();
    thread->result = retval;
!   _endthreadex (0); /* calls ExitThread (0) */
  }
  
  #endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]