patacongo edited a comment on issue #587: pthread_mutex_lock() does not resume 
waiting after signal
URL: https://github.com/apache/incubator-nuttx/issues/587#issuecomment-601276937
 
 
   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 interrupts:
   
       544 static inline int nxsem_wait_uninterruptible(FAR sem_t *sem)
       545 {
       546   int ret;
       547
       548   do
       549     {
       550       /* Take the semaphore (perhaps waiting) */
       551
       552       ret = nxsem_wait(sem);
       553     }
       554   while (ret == -EINTR || ret == -ECANCELED);
       555
       556   return ret;
       557 }
   
   It also breaks thread cancellation.  When cancellation points 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.  Since the loop 
prevents the task from exiting the cancellation point, it will prent the task 
from being terminated.
   
   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 a 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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to