diff options
Diffstat (limited to 'pthread_win32_attach_detach_np.c')
-rw-r--r-- | pthread_win32_attach_detach_np.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c index 6947080..191b0b0 100644 --- a/pthread_win32_attach_detach_np.c +++ b/pthread_win32_attach_detach_np.c @@ -261,15 +261,32 @@ pthread_win32_thread_detach_np () */ ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); - if (sp != NULL) + if (sp != NULL) // otherwise Win32 thread with no implicit POSIX handle. { + ptw32_callUserDestroyRoutines (sp->ptHandle); + + (void) pthread_mutex_lock (&sp->cancelLock); + sp->state = PThreadStateLast; /* - * Detached threads have their resources automatically - * cleaned up upon exit (others must be 'joined'). + * If the thread is joinable at this point then it MUST be joined + * or detached explicitly by the application. */ + (void) pthread_mutex_unlock (&sp->cancelLock); + if (sp->detachState == PTHREAD_CREATE_DETACHED) { ptw32_threadDestroy (sp->ptHandle); + +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) + /* + * See documentation for endthread vs endthreadex. + */ + if (sp->threadH != 0) + { + CloseHandle (sp->threadH); + } +#endif + TlsSetValue (ptw32_selfThreadKey->key, NULL); } } |