commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] POSIX threading library branch, master, updated. 5ab516af0779a7fd7


From: Richard Braun
Subject: [SCM] POSIX threading library branch, master, updated. 5ab516af0779a7fd74ad893c7c67960df6ede065
Date: Sun, 03 Feb 2013 23:06:39 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "POSIX threading library".

The branch, master has been updated
       via  5ab516af0779a7fd74ad893c7c67960df6ede065 (commit)
      from  14eeff65f732d77bc8d93bd5e1979fa6083b66d8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5ab516af0779a7fd74ad893c7c67960df6ede065
Author: Richard Braun <address@hidden>
Date:   Sun Feb 3 16:06:51 2013 +0100

    Fix pthread timeout handling and cancellation issues
    
    This patch solves two issues. The first one is cancellation handling
    when a cancellation request is sent before reaching a cancellation
    point (namely, pthread_cond_{timed,}wait). Cancellation is implemented
    by pushing an appropriate cleanup handler and switching to
    PTHREAD_CANCEL_ASYNCHRONOUS type. The main problem is that it doesn't
    handle pending requests, only a cancellation that occurs while blocking.
    Other problems occur when trying to correctly handle a timeout and a
    cancellation request through the cleanup routine.
    
    The other issue is correctly handling timeouts. This problem was already
    well known, as explained by the following comment :
    
    "FIXME: What do we do if we get a wakeup message before we disconnect
    ourself?  It may remain until the next time we block."
    
    In addition, the prevp thread member is inconsistently used. It is
    sometimes accessed while protected by the appropriate queue lock to
    determine whether a thread is still queued, while at times, threads
    are unqueued without holding a lock, as in pthread_cond_broadcast :
    
      /* We can safely walk the list of waiting threads without holding
         the lock since it is now decoupled from the condition.  */
      __pthread_dequeuing_iterate (wakeup, wakeup)
        __pthread_wakeup (wakeup);
    
    This is the root cause that triggers some assertion failures.
    
    The solution brought by this patch is to consistently use the prevp link
    to determine if both a thread has been unqueued and if a wakeup message
    has been sent (both are needed to wake up a thread). A thread unblocked
    because of a timeout can now accurately determine if it needs to drain
    its message queue. A direct improvement is that the message queue size
    can be limited to one message, and wakeups are guaranteed to be
    non-blocking, which allows safely calling __pthread_wakeup from critical
    sections.
    
    As it now affects the cleanup cancellation routine of
    __pthread_cond_timedwait_internal, cancellation is reworked as well.
    Cancellation type is forced to PTHREAD_CANCEL_DEFERRED during the call,
    and actually checked on both entry and return. A hook is set by the
    blocking thread so that the waker doesn't need to know about the call
    implementation. Cancellation members are now protected with a mutex for
    truely safe access.
    
    * pthread/pt-alloc.c (initialize_pthread): Initialize the new `cancel_lock',
    `cancel_hook' and `cancel_hook_args' fields.
    * pthread/pt-cancel.c (pthread_cancel): Rework cancellation handling.
    * pthread/pt-internal.h (struct __pthread): Add `cancel_lock', `cancel_hook'
    and `cancel_hook_args' fields.
    (__pthread_dequeue): Assert thread->prevp isn't NULL.
    * pthread/pt-join.c (pthread_join): Describe how the cancellation point is
    implemented.
    * pthread/pt-setcancelstate.c (__pthread_setcancelstate): Lock the given
    thread cancellation lock when switching state.
    * pthread/pt-setcanceltype.c (__pthread_setcanceltype): Likewise for
    cancellation type.
    * pthread/pt-testcancel.c (pthread_testcancel): Likewise for pending
    cancellations.
    * sysdeps/generic/pt-cond-brdcast.c (__pthread_cond_broadcast): Dequeue
    and wake up threads with condition locked.
    * sysdeps/generic/pt-cond-signal.c (cond_signal): Remove function, move
    implementation to ...
    (__pthread_cond_signal): ... this function. Remove unused `unblocked'
    variable.
    * sysdeps/generic/pt-cond-timedwait.c (struct cancel_ctx): New structure.
    (cancel_hook): New static function.
    (__pthread_cond_timedwait_internal): Fix cancellation and timeout handling.
    * sysdeps/generic/pt-mutex-timedlock.c
    (__pthread_mutex_timedlock_internal): Fix timeout handling.
    * sysdeps/generic/pt-rwlock-timedrdlock.c
    (__pthread_rwlock_timedrdlock_internal): Likewise.
    * sysdeps/generic/pt-rwlock-timedwrlock.c
    (__pthread_rwlock_timedwrlock_internal): Likewise.
    * sysdeps/generic/pt-rwlock-unlock.c (pthread_rwlock_unlock): Dequeue and
    wake up threads with rwlock internal lock held.
    * sysdeps/generic/sem-timedwait.c (__sem_timedwait_internal): Fix timeout
    handling.
    * sysdeps/mach/hurd/pt-docancel.c (__pthread_do_cancel): Unlock the given
    thread cancellation lock.
    * sysdeps/mach/pt-thread-alloc.c (create_wakeupmsg): Limit the message
    queue size of the wakeup port to 1.
     * sysdeps/mach/pt-wakeup.c (__pthread_wakeup): Call __mach_msg in a
    non-blocking way.

-----------------------------------------------------------------------

Summary of changes:
 pthread/pt-alloc.c                      |    3 +
 pthread/pt-cancel.c                     |   27 +++++-
 pthread/pt-internal.h                   |   11 ++-
 pthread/pt-join.c                       |    2 +
 pthread/pt-setcancelstate.c             |    2 +
 pthread/pt-setcanceltype.c              |    2 +
 pthread/pt-testcancel.c                 |    7 ++-
 sysdeps/generic/pt-cond-brdcast.c       |    8 +--
 sysdeps/generic/pt-cond-signal.c        |   23 +----
 sysdeps/generic/pt-cond-timedwait.c     |  147 ++++++++++++++++++++++---------
 sysdeps/generic/pt-mutex-timedlock.c    |   47 ++++++----
 sysdeps/generic/pt-rwlock-timedrdlock.c |   49 ++++++-----
 sysdeps/generic/pt-rwlock-timedwrlock.c |   50 ++++++-----
 sysdeps/generic/pt-rwlock-unlock.c      |   13 +--
 sysdeps/generic/sem-timedwait.c         |   51 ++++++-----
 sysdeps/mach/hurd/pt-docancel.c         |    2 +
 sysdeps/mach/pt-thread-alloc.c          |    4 +
 sysdeps/mach/pt-wakeup.c                |    4 +-
 18 files changed, 292 insertions(+), 160 deletions(-)


hooks/post-receive
-- 
POSIX threading library



reply via email to

[Prev in Thread] Current Thread [Next in Thread]