public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5383] libstdc++: Fix testsuite helper functions [PR 97936]
@ 2020-11-25 18:37 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-11-25 18:37 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:f76cad692a62d44ed32d010200bad74f36c73092
commit r11-5383-gf76cad692a62d44ed32d010200bad74f36c73092
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Nov 25 14:39:54 2020 +0000
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:
---
.../29_atomics/atomic/wait_notify/bool.cc | 1 -
.../29_atomics/atomic/wait_notify/generic.cc | 1 -
.../29_atomics/atomic/wait_notify/pointers.cc | 1 -
.../29_atomics/atomic_flag/wait_notify/1.cc | 1 -
.../29_atomics/atomic_float/wait_notify.cc | 1 -
.../29_atomics/atomic_integral/wait_notify.cc | 1 -
.../testsuite/util/atomic/wait_notify_util.h | 24 ++++++++++++++++++----
7 files changed, 20 insertions(+), 10 deletions(-)
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 29781c6e135..c14a2391d68 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 629556a9d2d..988fe7b334f 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 f54961f893d..87830236e0e 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 763d3e77159..991713fbcde 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 8f9e4a39a21..134eff39e1b 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 762583cf8c7..c65379cba61 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 a319e8b60a6..f5fff4af4e4 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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-25 18:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 18:37 [gcc r11-5383] libstdc++: Fix testsuite helper functions [PR 97936] Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).