From 46ae637c4ef03a921d4a06baf99219c6149a7d20 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 15 May 2005 15:28:24 +0000 Subject: '' --- pthread_win32_attach_detach_np.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'pthread_win32_attach_detach_np.c') 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); } } -- cgit v1.2.3