diff options
Diffstat (limited to 'pthread_win32_attach_detach_np.c')
-rw-r--r-- | pthread_win32_attach_detach_np.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c index 8116dd7..65e0913 100644 --- a/pthread_win32_attach_detach_np.c +++ b/pthread_win32_attach_detach_np.c @@ -190,15 +190,35 @@ pthread_win32_thread_detach_np () if (sp != NULL) // otherwise Win32 thread with no implicit POSIX handle. { + ptw32_mcs_local_node_t stateLock; ptw32_callUserDestroyRoutines (sp->ptHandle); - (void) pthread_mutex_lock (&sp->cancelLock); + ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); sp->state = PThreadStateLast; /* * 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); + ptw32_mcs_lock_release (&stateLock); + + /* + * Robust Mutexes + */ + while (sp->robustMxList != NULL) + { + pthread_mutex_t mx = sp->robustMxList->mx; + ptw32_robust_mutex_remove(&mx, sp); + (void) PTW32_INTERLOCKED_EXCHANGE( + (LPLONG)&mx->robustNode->stateInconsistent, + -1L); + /* + * If there are no waiters then the next thread to block will + * sleep, wakeup immediately and then go back to sleep. + * See pthread_mutex_lock.c. + */ + SetEvent(mx->event); + } + if (sp->detachState == PTHREAD_CREATE_DETACHED) { |