aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorThomas Rodgers <rodgert@appliantology.com>2022-02-09 12:29:19 -0800
committerThomas Rodgers <rodgert@appliantology.com>2022-02-09 12:30:51 -0800
commit4cf3c339815cdfa636b25a512f91b63d7c313fd6 (patch)
treed5b10af825688eb59925bcdb329c3a0990ba6e6e /libstdc++-v3
parentf0caa45aa7adacf4c0f1ca76a886028a5b54d1b3 (diff)
downloadgcc-4cf3c339815cdfa636b25a512f91b63d7c313fd6.zip
gcc-4cf3c339815cdfa636b25a512f91b63d7c313fd6.tar.gz
gcc-4cf3c339815cdfa636b25a512f91b63d7c313fd6.tar.bz2
libstdc++: Fix deadlock in atomic wait [PR104442]
This issue was observed as a deadlock in 29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is "laundered" (e.g. type T* does not suffice as a waitable address for the platform's native waiting primitive), the address waited is that of the _M_ver member of __waiter_pool_base, so several threads may wait on the same address for unrelated atomic<T> objects. As noted in the PR, the implementation correctly exits the wait for the thread whose data changed, but not for any other threads waiting on the same address. As noted in the PR the __waiter::_M_do_wait_v member was correctly exiting but the other waiters were not reloading the value of _M_ver before re-entering the wait. Moving the spin call inside the loop accomplishes this, and is consistent with the predicate accepting version of __waiter::_M_do_wait. libstdc++-v3/ChangeLog: PR libstdc++/104442 * include/bits/atomic_wait.h (__waiter::_M_do_wait_v): Move spin loop inside do loop so that threads failing the wait, reload _M_ver.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/atomic_wait.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index d7de0d7..6ce7f93 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -388,12 +388,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_M_do_wait_v(_Tp __old, _ValFn __vfn)
{
- __platform_wait_t __val;
- if (__base_type::_M_do_spin_v(__old, __vfn, __val))
- return;
-
do
{
+ __platform_wait_t __val;
+ if (__base_type::_M_do_spin_v(__old, __vfn, __val))
+ return;
__base_type::_M_w._M_do_wait(__base_type::_M_addr, __val);
}
while (__detail::__atomic_compare(__old, __vfn()));