olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone
077c9d
commit aa8a3e4cdef20c50cb20f008864fff05cbfbdf29
077c9d
Author: Martin Kuchta <martin.kuchta@netapp.com>
077c9d
Date:   Mon Aug 27 18:54:46 2018 +0200
077c9d
077c9d
    pthread_cond_broadcast: Fix waiters-after-spinning case [BZ #23538]
077c9d
    
077c9d
    (cherry picked from commit 99ea93ca31795469d2a1f1570f17a5c39c2eb7e2)
077c9d
077c9d
diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c
077c9d
index 8e425eb01eceabec..479e54febb417675 100644
077c9d
--- a/nptl/pthread_cond_common.c
077c9d
+++ b/nptl/pthread_cond_common.c
077c9d
@@ -405,8 +405,12 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq,
077c9d
 	{
077c9d
 	  /* There is still a waiter after spinning.  Set the wake-request
077c9d
 	     flag and block.  Relaxed MO is fine because this is just about
077c9d
-	     this futex word.  */
077c9d
-	  r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1);
077c9d
+	     this futex word.
077c9d
+
077c9d
+	     Update r to include the set wake-request flag so that the upcoming
077c9d
+	     futex_wait only blocks if the flag is still set (otherwise, we'd
077c9d
+	     violate the basic client-side futex protocol).  */
077c9d
+	  r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1) | 1;
077c9d
 
077c9d
 	  if ((r >> 1) > 0)
077c9d
 	    futex_wait_simple (cond->__data.__g_refs + g1, r, private);