[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] [RFC] Fix pthread timeout handling and cancellation issues
From: |
Richard Braun |
Subject: |
Re: [PATCH] [RFC] Fix pthread timeout handling and cancellation issues |
Date: |
Thu, 24 Jan 2013 12:20:50 +0100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Thu, Jan 24, 2013 at 12:14:44AM +0100, Richard Braun wrote:
> diff --git a/pthread/pt-cancel.c b/pthread/pt-cancel.c
> index d19c557..3698cce 100644
> --- a/pthread/pt-cancel.c
> +++ b/pthread/pt-cancel.c
> @@ -31,9 +31,31 @@ pthread_cancel (pthread_t t)
> if (! p)
> return ESRCH;
>
> + __pthread_mutex_lock (&p->cancel_lock);
> + if (p->cancel_pending)
> + {
> + __pthread_mutex_unlock (&p->cancel_lock);
> + return 0;
> + }
> +
> p->cancel_pending = 1;
> - if (p->cancel_state == PTHREAD_CANCEL_ENABLE
> - && p->cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS)
> +
> + if (p->cancel_state != PTHREAD_CANCEL_ENABLE)
> + {
> + __pthread_mutex_unlock (&p->cancel_lock);
> + return 0;
> + }
> +
> + /* Thread blocking on a cancellation point. Invoke hook to unblock.
> + See __pthread_cond_timedwait_internal. */
> + if (p->cancel_hook != NULL)
> + {
> + assert (p->cancel_type == PTHREAD_CANCEL_DEFERRED);
> + p->cancel_hook (p->cancel_hook_arg);
> + __pthread_mutex_unlock (&p->cancel_lock);
> + }
> + else if (p->cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS)
> + /* CANCEL_LOCK is unlocked by this call. */
> err = __pthread_do_cancel (p);
There is an obvious locking issue here where pthread_cancel could return
while the cancel lock hasn't been released. Consider it fixed.
--
Richard Braun