summaryrefslogtreecommitdiff
path: root/pthread_win32_attach_detach_np.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-05-15 15:28:24 +0000
committerrpj <rpj>2005-05-15 15:28:24 +0000
commit46ae637c4ef03a921d4a06baf99219c6149a7d20 (patch)
treeca25c87f4285954f598d6f9b11b906d74b24750d /pthread_win32_attach_detach_np.c
parentd4a22be21479c3b52e0ba2d3cfb150a98c426422 (diff)
''
Diffstat (limited to 'pthread_win32_attach_detach_np.c')
-rw-r--r--pthread_win32_attach_detach_np.c23
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);
}
}