From a824c43d3f20fc5722c5fd8f0f942f632b961723 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 16 May 2005 15:42:44 +0000 Subject: '' --- pthread_win32_attach_detach_np.c | 20 +++++++++++++++++--- 1 file changed, 17 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..d839c70 100644 --- a/pthread_win32_attach_detach_np.c +++ b/pthread_win32_attach_detach_np.c @@ -261,15 +261,29 @@ 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. { + HANDLE threadH = sp->threadH; + + 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 (threadH != 0) + { + CloseHandle (threadH); + } + TlsSetValue (ptw32_selfThreadKey->key, NULL); } } -- cgit v1.2.3