On 25/11/20 10:35 +0000, Jonathan Wakely wrote:
I've pushed that as ad9cbcee543ecccd79fa49dafcd925532d2ce210 but there are still other FAILs to be fixed.
I think the other FAILs are due to a race condition in the tests, fixed by this patch. Tested x86_64-linux, powerpc64le-linux, sparc-solaris2.11 and powerpc-aix. Committed to trunk. I'll keep an eye on the testresults to see if this really fixes it or not.
commit f76cad692a62d44ed32d010200bad74f36c73092 Author: Jonathan Wakely <jwak...@redhat.com> Date: Wed Nov 25 14:39:54 2020 libstdc++: Fix testsuite helper functions [PR 97936] This fixes a race condition in the util/atomic/wait_notify_util.h header used by several tests, which should make the tests work properly. libstdc++-v3/ChangeLog: PR libstdc++/97936 * testsuite/29_atomics/atomic/wait_notify/bool.cc: Re-eneable test. * testsuite/29_atomics/atomic/wait_notify/generic.cc: Likewise. * testsuite/29_atomics/atomic/wait_notify/pointers.cc: Likewise. * testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise. * testsuite/29_atomics/atomic_float/wait_notify.cc: Likewise. * testsuite/29_atomics/atomic_integral/wait_notify.cc: Likewise. * testsuite/util/atomic/wait_notify_util.h: Fix missed notifications by making the new thread wait until the parent thread is waiting on the condition variable. diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc index 29781c6e1357..c14a2391d68b 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc @@ -2,7 +2,6 @@ // { dg-do run { target c++2a } } // { dg-require-gthreads "" } // { dg-additional-options "-pthread" { target pthread } } -// { dg-skip-if "broken" { ! *-*-*linux } } // Copyright (C) 2020 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.cc index 629556a9d2d0..988fe7b334f3 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.cc @@ -2,7 +2,6 @@ // { dg-do run { target c++2a } } // { dg-require-gthreads "" } // { dg-additional-options "-pthread" { target pthread } } -// { dg-skip-if "broken" { ! *-*-*linux } } // Copyright (C) 2020 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc index f54961f893d4..87830236e0ee 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc @@ -2,7 +2,6 @@ // { dg-do run { target c++2a } } // { dg-additional-options "-pthread" { target pthread } } // { dg-require-gthreads "" } -// { dg-skip-if "broken" { ! *-*-*linux } } // Copyright (C) 2020 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc index 763d3e77159c..991713fbcdee 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc @@ -2,7 +2,6 @@ // { dg-do run { target c++2a } } // { dg-require-gthreads "" } // { dg-additional-options "-pthread" { target pthread } } -// { dg-skip-if "broken" { ! *-*-*linux } } // Copyright (C) 2020 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc b/libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc index 8f9e4a39a21f..134eff39e1b1 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc @@ -3,7 +3,6 @@ // { dg-require-gthreads "" } // { dg-additional-options "-pthread" { target pthread } } // { dg-add-options libatomic } -// { dg-skip-if "broken" { ! *-*-*linux } } // Copyright (C) 2020 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc b/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc index 762583cf8c76..c65379cba619 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc @@ -3,7 +3,6 @@ // { dg-require-gthreads "" } // { dg-add-options libatomic } // { dg-additional-options "-pthread" { target pthread } } -// { dg-skip-if "broken" { *-*-* } } // Copyright (C) 2020 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h b/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h index a319e8b60a69..f5fff4af4e49 100644 --- a/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h +++ b/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h @@ -34,16 +34,20 @@ Tp check_wait_notify(Tp val1, Tp val2) std::mutex m; std::condition_variable cv; + std::unique_lock<std::mutex> l(m); std::atomic<Tp> a(val1); std::thread t([&] { + { + // This ensures we block until cv.wait(l) starts. + std::lock_guard<std::mutex> ll(m); + } cv.notify_one(); a.wait(val1); if (a.load() != val2) a = val1; }); - std::unique_lock<std::mutex> l(m); cv.wait(l); std::this_thread::sleep_for(100ms); a.store(val2); @@ -59,10 +63,15 @@ Tp check_wait_notify(Tp val1, Tp val2) std::mutex m; std::condition_variable cv; + std::unique_lock<std::mutex> l(m); std::atomic<Tp> a(val1); std::thread t([&] { + { + // This ensures we block until cv.wait(l) starts. + std::lock_guard<std::mutex> ll(m); + } cv.notify_one(); a.wait(val1); auto v = a.load(); @@ -70,7 +79,6 @@ Tp check_wait_notify(Tp val1, Tp val2) if (__builtin_memcmp(&v, &val2, sizeof(Tp)) != 0) a = val1; }); - std::unique_lock<std::mutex> l(m); cv.wait(l); std::this_thread::sleep_for(100ms); a.store(val2); @@ -87,16 +95,20 @@ Tp check_atomic_wait_notify(Tp val1, Tp val2) std::mutex m; std::condition_variable cv; + std::unique_lock<std::mutex> l(m); std::atomic<Tp> a(val1); std::thread t([&] { + { + // This ensures we block until cv.wait(l) starts. + std::lock_guard<std::mutex> ll(m); + } cv.notify_one(); std::atomic_wait(&a, val1); if (a.load() != val2) a = val1; }); - std::unique_lock<std::mutex> l(m); cv.wait(l); std::this_thread::sleep_for(100ms); a.store(val2); @@ -112,10 +124,15 @@ Tp check_atomic_wait_notify(Tp val1, Tp val2) std::mutex m; std::condition_variable cv; + std::unique_lock<std::mutex> l(m); std::atomic<Tp> a(val1); std::thread t([&] { + { + // This ensures we block until cv.wait(l) starts. + std::lock_guard<std::mutex> ll(m); + } cv.notify_one(); std::atomic_wait(&a, val1); auto v = a.load(); @@ -123,7 +140,6 @@ Tp check_atomic_wait_notify(Tp val1, Tp val2) if (__builtin_memcmp(&v, &val2, sizeof(Tp)) != 0) a = val1; }); - std::unique_lock<std::mutex> l(m); cv.wait(l); std::this_thread::sleep_for(100ms); a.store(val2);