pthread_cond_broadcast: Fix waiters-after-spinning case [BZ #23538]

(cherry picked from commit 99ea93ca31)
This commit is contained in:
Martin Kuchta 2018-08-27 18:54:46 +02:00 committed by Florian Weimer
parent c9570bd2f5
commit 174709d879
3 changed files with 15 additions and 2 deletions

View File

@ -1,3 +1,11 @@
2018-08-27 Martin Kuchta <martin.kuchta@netapp.com>
Torvald Riegel <triegel@redhat.com>
[BZ #23538]
* nptl/pthread_cond_common.c (__condvar_quiesce_and_switch_g1):
Update r to include the set wake-request flag if waiters are
remaining after spinning.
2018-07-29 H.J. Lu <hongjiu.lu@intel.com> 2018-07-29 H.J. Lu <hongjiu.lu@intel.com>
[BZ #23459] [BZ #23459]

1
NEWS
View File

@ -146,6 +146,7 @@ The following bugs are resolved with this release:
[23236] Harden function pointers in _IO_str_fields [23236] Harden function pointers in _IO_str_fields
[23313] libio: Disable vtable validation in case of interposition [23313] libio: Disable vtable validation in case of interposition
[23349] Various glibc headers no longer compatible with <linux/time.h> [23349] Various glibc headers no longer compatible with <linux/time.h>
[23538] pthread_cond_broadcast: Fix waiters-after-spinning case
[23363] stdio-common/tst-printf.c has non-free license [23363] stdio-common/tst-printf.c has non-free license
[23456] Wrong index_cpu_LZCNT [23456] Wrong index_cpu_LZCNT
[23459] COMMON_CPUID_INDEX_80000001 isn't populated for Intel processors [23459] COMMON_CPUID_INDEX_80000001 isn't populated for Intel processors

View File

@ -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 /* There is still a waiter after spinning. Set the wake-request
flag and block. Relaxed MO is fine because this is just about flag and block. Relaxed MO is fine because this is just about
this futex word. */ this futex word.
r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1);
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) if ((r >> 1) > 0)
futex_wait_simple (cond->__data.__g_refs + g1, r, private); futex_wait_simple (cond->__data.__g_refs + g1, r, private);