nuttx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] [incubator-nuttx] patacongo commented on issue #587: pthread_mutex_lock() does not resume waiting after signal
Date Thu, 19 Mar 2020 16:26:30 GMT
patacongo commented on issue #587: pthread_mutex_lock() does not resume waiting after signal
   NOTE:  Passing the value false to pthread_mutex_take() is not a solution.
   That argument is passed to pthread_sem_take() and if the argument is false it calls:
       117       if (abs_timeout == NULL)
       118         {
       119           ret = nxsem_wait_uninterruptible(sem);
       120         }
       121       else
       122         {
       123           ret = nxsem_timedwait_uninterruptible(sem, abs_timeout);
       124         }
   But nxsem_wait_uninterruptble does more than just ignore signal interupts:
       544 static inline int nxsem_wait_uninterruptible(FAR sem_t *sem)
       545 {
       546   int ret;
       548   do
       549     {
       550       /* Take the semaphore (perhaps waiting) */
       552       ret = nxsem_wait(sem);
       553     }
       554   while (ret == -EINTR || ret == -ECANCELED);
       556   return ret;
       557 }
   It also breaks thread cancellation.  When cancellation pointers are enabled, semaphore
waits will be awakened with ECANCELED and must return.  In the deferred cancellation mode
all resources will be cleaned-up and that task will terminated when it attempts to exit the
cancellation point.
   The above breaks thread cancellation because in the event that the thread is cancelled,
it simply loops back and waits again.  The thread cannot be cancelled in the recommended deferred
cancellation most.  That is seriaous OS breakage.
   This is another bug in the existing implementation.  ALL semaphore waits must return in
the event of thread cancellation, otherwise thread cancellation is broken (it is broken in
many cases).
   A better solution in  pthread_sem_take() would be to set up a sigprocmask and block relevant
signals instead of calling nxsem_wait_uninterruptible().  That is too brutal.  All signals
should be blocked except (1) the signal that wakes up the timed event and (2) any signals
associated with thread cancellation.

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

View raw message