diff options
Diffstat (limited to 'nptl/pthread_cond_common.c')
-rw-r--r-- | nptl/pthread_cond_common.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index 8e425eb01e..1c84bb87c1 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -1,5 +1,5 @@ /* pthread_cond_common -- shared code for condition variable. - Copyright (C) 2016-2018 Free Software Foundation, Inc. + Copyright (C) 2016-2019 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -14,7 +14,7 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ + <https://www.gnu.org/licenses/>. */ #include <atomic.h> #include <stdint.h> @@ -405,8 +405,12 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, { /* There is still a waiter after spinning. Set the wake-request flag and block. Relaxed MO is fine because this is just about - this futex word. */ - r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1); + this futex word. + + Update r to include the set wake-request flag so that the upcoming + futex_wait only blocks if the flag is still set (otherwise, we'd + violate the basic client-side futex protocol). */ + r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1) | 1; if ((r >> 1) > 0) futex_wait_simple (cond->__data.__g_refs + g1, r, private); |