summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/misc.c b/misc.c
index 0fbff03..63ec45a 100644
--- a/misc.c
+++ b/misc.c
@@ -355,9 +355,20 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout)
if (self != NULL && !self->implicit)
{
/*
- * Thread started with pthread_create
+ * Thread started with pthread_create.
+ * Make sure we haven't been async-canceled in the meantime.
*/
- ptw32_throw(PTW32_EPS_CANCEL);
+ (void) pthread_mutex_lock(&self->cancelLock);
+ if (self->state < PThreadStateCanceling)
+ {
+ self->state = PThreadStateCanceling;
+ self->cancelState = PTHREAD_CANCEL_DISABLE;
+ (void) pthread_mutex_unlock(&self->cancelLock);
+ ptw32_throw(PTW32_EPS_CANCEL);
+
+ /* Never reached */
+ }
+ (void) pthread_mutex_unlock(&self->cancelLock);
}
/* Should never get to here. */