This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 45fd32d27bfd2edf9686f2ffb21995c3154fb7f5
Author: ganjing <[email protected]>
AuthorDate: Mon Dec 15 19:19:14 2025 +0800

    libc/pthread: Drop the wait count of a timed out condition waiter.
    
    pthread_cond_clockwait() counts the waiter in wait_count before it
    blocks, and only pthread_cond_signal() and pthread_cond_broadcast()
    drop the count of the waiters they wake.  A waiter whose wait timed out
    kept its count, so pthread_cond_destroy() returned EBUSY afterwards,
    and a later pthread_cond_broadcast() posted the semaphore for waiters
    that were gone.
    
    Drop the count when the wait times out.
    
    Assisted-by: Kiro:auto
    Signed-off-by: ganjing <[email protected]>
---
 libs/libc/pthread/pthread_condclockwait.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libs/libc/pthread/pthread_condclockwait.c 
b/libs/libc/pthread/pthread_condclockwait.c
index cb37877371b..f49ed6659b8 100644
--- a/libs/libc/pthread/pthread_condclockwait.c
+++ b/libs/libc/pthread/pthread_condclockwait.c
@@ -144,7 +144,16 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
       sinfo("Re-locking...\n");
 
       status = pthread_mutex_restorelock(mutex, nlocks);
-      if (ret == 0)
+
+      /* When the wait times out (ETIMEDOUT), we must decrement
+       * wait_count to maintain proper accounting.
+       */
+
+      if (ret == ETIMEDOUT)
+        {
+          atomic_sub(COND_WAIT_COUNT(cond), 1);
+        }
+      else if (ret == 0)
         {
           ret = status;
         }

Reply via email to