From commits-return-5271-archive-asf-public=cust-asf.ponee.io@nuttx.apache.org Thu Mar 19 16:26:32 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id A4788180661 for ; Thu, 19 Mar 2020 17:26:31 +0100 (CET) Received: (qmail 70422 invoked by uid 500); 19 Mar 2020 16:26:31 -0000 Mailing-List: contact commits-help@nuttx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nuttx.apache.org Delivered-To: mailing list commits@nuttx.apache.org Received: (qmail 70411 invoked by uid 99); 19 Mar 2020 16:26:30 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Mar 2020 16:26:30 +0000 From: GitBox To: commits@nuttx.apache.org Subject: [GitHub] [incubator-nuttx] patacongo commented on issue #587: pthread_mutex_lock() does not resume waiting after signal Message-ID: <158463519079.21064.496664812727124552.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Thu, 19 Mar 2020 16:26:30 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit patacongo commented 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 interupts: 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 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: users@infra.apache.org With regards, Apache Git Services