Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-26 Thread Jonathan Wakely via Gcc-patches

On 25/11/20 18:39 +, Jonathan Wakely wrote:

On 25/11/20 10:35 +, 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.


This fixes some more races of the same kind, in different tiles.

Tested as above. Committed to trunk.


commit 10522ed1089277e2aa6cd708205aa5c730179cf0
Author: Jonathan Wakely 
Date:   Thu Nov 26 12:55:47 2020

libstdc++: Fix some more deadlocks in tests [PR 97936]

The missed notifications fixed in r11-5383 also happen in some other
tests which have similar code.

libstdc++-v3/ChangeLog:

PR libstdc++/97936
* testsuite/29_atomics/atomic/wait_notify/bool.cc: Fix missed
notifications by making the new thread wait until the parent
thread is waiting on the condition variable.
* testsuite/29_atomics/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise.
* testsuite/29_atomics/atomic_ref/wait_notify.cc: Likewise.

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 c14a2391d68b..1fc014911737 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc
@@ -36,11 +36,16 @@ main ()
 
   std::mutex m;
   std::condition_variable cv;
+  std::unique_lock l(m);
 
   std::atomic a(false);
   std::atomic b(false);
   std::thread t([&]
 		{
+		  {
+		// This ensures we block until cv.wait(l) starts.
+		std::lock_guard ll(m);
+		  }
 		  cv.notify_one();
 		  a.wait(false);
 		  if (a.load())
@@ -48,7 +53,6 @@ main ()
 		  b.store(true);
 		}
 		});
-  std::unique_lock l(m);
   cv.wait(l);
   std::this_thread::sleep_for(100ms);
   a.store(true);
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 87830236e0ee..3b699e9133b2 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc
@@ -36,6 +36,7 @@ main ()
 
   std::mutex m;
   std::condition_variable cv;
+  std::unique_lock l(m);
 
   long aa;
   long bb;
@@ -43,12 +44,15 @@ main ()
   std::atomic a(nullptr);
   std::thread t([&]
 		{
+		  {
+		// This ensures we block until cv.wait(l) starts.
+		std::lock_guard ll(m);
+		  }
 		  cv.notify_one();
 		  a.wait(nullptr);
 		  if (a.load() == )
 		a.store();
 		});
-  std::unique_lock l(m);
   cv.wait(l);
   std::this_thread::sleep_for(100ms);
   a.store();
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 991713fbcdee..5d5e06dde31c 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
@@ -36,18 +36,22 @@ main()
 
   std::mutex m;
   std::condition_variable cv;
+  std::unique_lock l(m);
 
   std::atomic_flag a;
   std::atomic_flag b;
   std::thread t([&]
 		{
+		  {
+		// This ensures we block until cv.wait(l) starts.
+		std::lock_guard ll(m);
+		  }
 		  cv.notify_one();
 		  a.wait(false);
 		  b.test_and_set();
 		  b.notify_one();
 		});
 
-  std::unique_lock l(m);
   cv.wait(l);
   std::this_thread::sleep_for(100ms);
   a.test_and_set();
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
index b38fc206d468..bc5a7d0d8bf9 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
@@ -37,17 +37,21 @@ Tp check_wait_notify(Tp val1, Tp val2)
 
   std::mutex m;
   std::condition_variable cv;
+  std::unique_lock l(m);
 
   Tp aa = val1;
   std::atomic_ref a(aa);
   std::thread t([&]
 		{
+		  {
+		// This ensures we block until cv.wait(l) starts.
+		std::lock_guard ll(m);
+		  }
 		  cv.notify_one();
 		  a.wait(val1);
 		  if (a.load() != val2)
 		a = val1;
 		});
-  std::unique_lock l(m);
   cv.wait(l);
   std::this_thread::sleep_for(100ms);
   a.store(val2);


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-25 Thread Jonathan Wakely via Gcc-patches

On 25/11/20 10:35 +, 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 
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 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-25 Thread Jonathan Wakely via Gcc-patches

On 25/11/20 10:35 +, Jonathan Wakely wrote:

On 25/11/20 01:07 +, Jonathan Wakely wrote:

On 24/11/20 23:45 +, Jonathan Wakely wrote:

On 21/11/20 16:36 -0800, H.J. Lu wrote:

On Sat, Nov 21, 2020 at 9:40 AM Jonathan Wakely via Gcc-patches
 wrote:


On 21/11/20 17:04 +, Jonathan Wakely wrote:

On 21/11/20 16:16 +0100, Andreas Schwab wrote:

In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
 from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
 from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
 from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')


I'm testing this.


I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test



I opened:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97936


I've disabled the failing tests for now. They can be re-enabled after
the problem is found and fixed.


I was finally able to reproduce the hangs, and I think this is the
fix:

--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -100,9 +100,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  auto __e = syscall (SYS_futex, static_cast(__addr),

static_cast(__futex_wait_flags::__wait_private),
  __val, nullptr);
-   if (!__e)
+   if (!__e || errno == EAGAIN)
break;
-   else if (!(errno == EINTR || errno == EAGAIN))
+   else if (errno != EINTR)
__throw_system_error(__e);
}
 }

The problem is that we're going into a busy loop when SYS_futex
returns EAGAIN, but that means the current value doesn't match the
expected value, so we should return not keep waiting for the value to
change.


I've pushed that as ad9cbcee543ecccd79fa49dafcd925532d2ce210 but there
are still other FAILs to be fixed.


Except that what I pushed was not what I wrote above, as noticed by
Jakub. I need to get more sleep.

Fixed with this patch, pushed to trunk.


commit a5ccfd04605d940daded7e95474389f1c7dfad61
Author: Jonathan Wakely 
Date:   Wed Nov 25 12:16:07 2020

libstdc++: Fix silly typos [PR 97936]

libstdc++-v3/ChangeLog:

PR libstdc++/97936
* include/bits/atomic_wait.h 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-25 Thread Jonathan Wakely via Gcc-patches

On 25/11/20 01:07 +, Jonathan Wakely wrote:

On 24/11/20 23:45 +, Jonathan Wakely wrote:

On 21/11/20 16:36 -0800, H.J. Lu wrote:

On Sat, Nov 21, 2020 at 9:40 AM Jonathan Wakely via Gcc-patches
 wrote:


On 21/11/20 17:04 +, Jonathan Wakely wrote:

On 21/11/20 16:16 +0100, Andreas Schwab wrote:

In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
  from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
  from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
  from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')


I'm testing this.


I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test



I opened:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97936


I've disabled the failing tests for now. They can be re-enabled after
the problem is found and fixed.


I was finally able to reproduce the hangs, and I think this is the
fix:

--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -100,9 +100,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   auto __e = syscall (SYS_futex, static_cast(__addr),
 
static_cast(__futex_wait_flags::__wait_private),
   __val, nullptr);
-   if (!__e)
+   if (!__e || errno == EAGAIN)
 break;
-   else if (!(errno == EINTR || errno == EAGAIN))
+   else if (errno != EINTR)
 __throw_system_error(__e);
 }
  }

The problem is that we're going into a busy loop when SYS_futex
returns EAGAIN, but that means the current value doesn't match the
expected value, so we should return not keep waiting for the value to
change.


I've pushed that as ad9cbcee543ecccd79fa49dafcd925532d2ce210 but there
are still other FAILs to be fixed.




Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-24 Thread Jonathan Wakely via Gcc-patches

On 24/11/20 23:45 +, Jonathan Wakely wrote:

On 21/11/20 16:36 -0800, H.J. Lu wrote:

On Sat, Nov 21, 2020 at 9:40 AM Jonathan Wakely via Gcc-patches
 wrote:


On 21/11/20 17:04 +, Jonathan Wakely wrote:

On 21/11/20 16:16 +0100, Andreas Schwab wrote:

In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
   from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
   from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
   from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')


I'm testing this.


I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test



I opened:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97936


I've disabled the failing tests for now. They can be re-enabled after
the problem is found and fixed.


I was finally able to reproduce the hangs, and I think this is the
fix:

--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -100,9 +100,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
auto __e = syscall (SYS_futex, static_cast(__addr),
  
static_cast(__futex_wait_flags::__wait_private),
__val, nullptr);
-   if (!__e)
+   if (!__e || errno == EAGAIN)
  break;
-   else if (!(errno == EINTR || errno == EAGAIN))
+   else if (errno != EINTR)
  __throw_system_error(__e);
  }
   }

The problem is that we're going into a busy loop when SYS_futex
returns EAGAIN, but that means the current value doesn't match the
expected value, so we should return not keep waiting for the value to
change.




Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-24 Thread Jonathan Wakely via Gcc-patches

On 21/11/20 16:36 -0800, H.J. Lu wrote:

On Sat, Nov 21, 2020 at 9:40 AM Jonathan Wakely via Gcc-patches
 wrote:


On 21/11/20 17:04 +, Jonathan Wakely wrote:
>On 21/11/20 16:16 +0100, Andreas Schwab wrote:
>>In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
>>from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) const':
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
>>In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
>>from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void std::__atomic_wait(const 
_Tp*, _Tp, _Pred)'
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
>>In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
>>from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 'bool')
>
>I'm testing this.

I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test



I opened:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97936


I've disabled the failing tests for now. They can be re-enabled after
the problem is found and fixed.

Committed to trunk.


commit a3313a2214a6253672ab4fa37a2dcf57fd0f8dce
Author: Jonathan Wakely 
Date:   Tue Nov 24 23:22:01 2020

libstdc++: Disable failing tests [PR 97936]

These tests are unstable and causing failures due to timeouts. Disable
them until the cause can be found, so that testing doesn't have to wait
for them to timeout.

libstdc++-v3/ChangeLog:

PR libstdc++/97936
PR libstdc++/97944
* testsuite/29_atomics/atomic_integral/wait_notify.cc: Disable.
Do not require pthreads, but add -pthread when appropriate.
* testsuite/30_threads/jthread/95989.cc: Likewise.
* testsuite/30_threads/latch/3.cc: Likewise.
* testsuite/30_threads/semaphore/try_acquire_until.cc: Likewise.

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 abf2bfdbee96..762583cf8c76 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc
@@ -1,8 +1,9 @@
-// { dg-options "-std=gnu++2a -pthread" }
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target pthread }
 // { dg-require-gthreads "" }
 // { dg-add-options libatomic }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-skip-if 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread David Edelsohn via Gcc-patches
On Mon, Nov 23, 2020 at 1:31 PM Jonathan Wakely  wrote:
>
> On 22/11/20 13:37 +, Jonathan Wakely via Libstdc++ wrote:
> >On Sun, 22 Nov 2020, 12:29 Iain Sandoe,  wrote:
> >
> >> thanks for looking at this over the weekend.
> >>
> >> Jonathan Wakely via Gcc-patches  wrote:
> >>
> >> > On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
> >> >  wrote:
> >> >> I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
> >> >> fixes.  And a few c++ failures with similar symptoms.  I'm not certain
> >> >> that it is due to this patch, but it's the likely suspect.
> >> > Yes, it's that patch.
> >> >
> >> > This should fix most of those errors, but I haven't finished testing
> >> > it, and can't commit it now anyway.
> >> > 
> >>
> >> with r11-5235 + this patch there are still quite a few fails on Darwin -
> >> but
> >> all seem to be the same ( so maybe only problem ;) ):
> >>   “sem_timedwait was not declared in this scope”.
> >>
> >> It looks like the semaphore header is optional in SUSv3 (AFAIK that’s still
> >> the claimed edition for Darwin) - and although Darwin has the semaphore
> >> header, it doesn’t seem to have an impl. of sem_timedwait.
> >>
> >> just:
> >> int sem_trywait(sem_t *);
> >> int sem_wait(sem_t *) ;
> >>
> >
> >
> >It probably depends on the _POSIX_TIMEOUTS option which MacOS doesn't
> >support (optional in POSIX 2001, but not 2008).
>
> Hopefully this fixes it, but I haven't tested it on darwin, only
> linux, aix and solaris.

This patch fixed the problems that I saw on AIX.  Thanks for addressing it!

Thanks, David


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 22/11/20 22:13 +0100, Stephan Bergmann wrote:

On 20/11/2020 23:44, Thomas Rodgers wrote:

Tested x86_64-pc-linux-gnu, committed.


Clang complains:


$ cat test.cc
#include 

$ clang++ --gcc-toolchain=~/gcc/trunk/inst -std=c++20 -fsyntax-only test.cc
In file included from test.cc:1:
In file included from 
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/semaphore:36:
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/bits/semaphore_base.h:145:22:
 error: no viable conversion from 'std::chrono::system_clock::time_point' (aka 
'time_point>>') 
to 'const std::__platform_semaphore::__clock_t' (aka 'const std::chrono::system_clock')
   const __clock_t __s_entry = __clock_t::now();
   ^   
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/chrono:1101:12: 
note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 
'std::chrono::system_clock::time_point' (aka 'time_point>>') to 'const std::chrono::system_clock &' for 
1st argument
   struct system_clock
  ^
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/chrono:1101:12: note: 
candidate constructor (the implicit move constructor) not viable: no known conversion from 
'std::chrono::system_clock::time_point' (aka 'time_point>>') to 'std::chrono::system_clock &&' for 1st argument
1 error generated.


which


diff --git a/libstdc++-v3/include/bits/semaphore_base.h 
b/libstdc++-v3/include/bits/semaphore_base.h
index 78a0b6ba26e..f25c9fdb325 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -142,7 +142,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   else
 {
   const typename _Clock::time_point __c_entry = _Clock::now();
-   const __clock_t __s_entry = __clock_t::now();
+   const __clock_t::time_point __s_entry = __clock_t::now();
   const auto __delta = __atime - __c_entry;
   const auto __s_atime = __s_entry + __delta;
   if (_M_try_acquire_until_impl(__s_atime))
~


would fix.


I just used 'auto'` instead.

Committed, thanks.

The fact this didn't error with GCC suggests we're missing some tests.


commit 1ccee0fbfa8e528b3671dfbf4dad5b6f67755e4c
Author: Jonathan Wakely 
Date:   Mon Nov 23 18:16:44 2020

libstdc++: Fix variable declared with wrong type

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h
(__platform_semaphore::_M_try_acquire_until): Fix type of
variable.

diff --git a/libstdc++-v3/include/bits/semaphore_base.h b/libstdc++-v3/include/bits/semaphore_base.h
index 0692f95f24f2..56333bbbfef7 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -141,7 +141,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	else
 	  {
 	const typename _Clock::time_point __c_entry = _Clock::now();
-	const __clock_t __s_entry = __clock_t::now();
+	const auto __s_entry = __clock_t::now();
 	const auto __delta = __atime - __c_entry;
 	const auto __s_atime = __s_entry + __delta;
 	if (_M_try_acquire_until_impl(__s_atime))


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 22/11/20 22:41 +0100, Stephan Bergmann wrote:

On 20/11/2020 23:44, Thomas Rodgers wrote:

Tested x86_64-pc-linux-gnu, committed.


...and there are multiple definition complaints from the linker 
because of two missing "include":



index 7b2682a577e..23ab2018ca8 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -223,7 +223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  { _M_w._M_do_wait(_M_version); }
};
-void
+inline void
__thread_relax() noexcept
{
#if defined __i386__ || defined __x86_64__
@@ -233,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
}
-void
+inline void
__thread_yield() noexcept
   {
#if defined _GLIBCXX_USE_SCHED_YIELD


Committed, thanks.


commit 0986d3bc621b12c3d0367bf7bd25927c7fbfc552
Author: Stephan Bergmann 
Date:   Mon Nov 23 18:14:44 2020

libstdc++: Fix linker errors due to missing 'inline' keywords

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h (__thread_relax, __thread_yield):
Add 'inline'.

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index a40cff124d7d..cd756f68de6d 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { _M_w._M_do_wait(_M_version); }
 };
 
-void
+inline void
 __thread_relax() noexcept
 {
 #if defined __i386__ || defined __x86_64__
@@ -234,9 +234,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 }
 
-void
+inline void
 __thread_yield() noexcept
-   {
+{
 #if defined _GLIBCXX_USE_SCHED_YIELD
  __gthread_yield();
 #endif


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 23/11/20 18:31 +, Jonathan Wakely wrote:

On 22/11/20 13:37 +, Jonathan Wakely via Libstdc++ wrote:

On Sun, 22 Nov 2020, 12:29 Iain Sandoe,  wrote:


thanks for looking at this over the weekend.

Jonathan Wakely via Gcc-patches  wrote:


On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
 wrote:

I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
fixes.  And a few c++ failures with similar symptoms.  I'm not certain
that it is due to this patch, but it's the likely suspect.

Yes, it's that patch.

This should fix most of those errors, but I haven't finished testing
it, and can't commit it now anyway.



with r11-5235 + this patch there are still quite a few fails on Darwin -
but
all seem to be the same ( so maybe only problem ;) ):
 “sem_timedwait was not declared in this scope”.

It looks like the semaphore header is optional in SUSv3 (AFAIK that’s still
the claimed edition for Darwin) - and although Darwin has the semaphore
header, it doesn’t seem to have an impl. of sem_timedwait.

just:
int sem_trywait(sem_t *);
int sem_wait(sem_t *) ;




It probably depends on the _POSIX_TIMEOUTS option which MacOS doesn't
support (optional in POSIX 2001, but not 2008).


Hopefully this fixes it, but I haven't tested it on darwin, only
linux, aix and solaris.

Committed.


With the patch this time ...


commit 92b47a321e14f98c524f6e67e7ecabad5afa7886
Author: Jonathan Wakely 
Date:   Mon Nov 23 17:17:09 2020

libstdc++: Add configure checks for semaphores

This moves the checks for POSIX semaphores to configure time. As well as
requiring  and SEM_VALUE_MAX, we also require the
sem_timedwait function. That was only optional in POSIX 2001 (and is
absent on Darwin).

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_CHECK_GTHREADS): Check for
* config.h.in: Regenerate.
* configure: Regenerate.
* include/bits/semaphore_base.h (_GLIBCXX_HAVE_POSIX_SEMAPHORE):
Check autoconf macro instead of defining it here.

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 486347b34d94..a4a0bb840181 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4089,6 +4089,43 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
 fi
   fi
 
+  AC_CHECK_HEADER(semaphore.h, [
+AC_MSG_CHECKING([for POSIX Semaphores and sem_timedwait])
+AC_TRY_COMPILE([
+	#include 
+	#include 
+	#include 
+  ],
+  [
+	#if !defined _POSIX_TIMEOUTS || _POSIX_TIMEOUTS <= 0
+	# error "POSIX Timeouts option not supported"
+	#elif !defined _POSIX_SEMAPHORES || _POSIX_SEMAPHORES <= 0
+	# error "POSIX Semaphores option not supported"
+	#else
+	#if defined SEM_VALUE_MAX
+	constexpr int sem_value_max = SEM_VALUE_MAX;
+	#elif defined _POSIX_SEM_VALUE_MAX
+	constexpr int sem_value_max = _POSIX_SEM_VALUE_MAX;
+	#else
+	# error "SEM_VALUE_MAX not available"
+	#endif
+	sem_t sem;
+	sem_init(, 0, sem_value_max);
+	struct timespec ts = { 0 };
+	sem_timedwait(, );
+	#endif
+  ],
+  [ac_have_posix_semaphore=yes],
+  [ac_have_posix_semaphore=no])],
+  [ac_have_posix_semaphore=no])
+
+  if test $ac_have_posix_semaphore = yes ; then
+AC_DEFINE(_GLIBCXX_HAVE_POSIX_SEMAPHORE,
+	  1,
+	  [Define to 1 if POSIX Semaphores with sem_timedwait are available in .])
+  fi
+  AC_MSG_RESULT([$ac_have_posix_semaphore])
+
   CXXFLAGS="$ac_save_CXXFLAGS"
   AC_LANG_RESTORE
 ])
diff --git a/libstdc++-v3/include/bits/semaphore_base.h b/libstdc++-v3/include/bits/semaphore_base.h
index 5e29d3783fe1..0692f95f24f2 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -39,11 +39,9 @@
 
 #include 
 
-#if __has_include()
+#ifdef _GLIBCXX_HAVE_POSIX_SEMAPHORE
+# include 
 # include 
-# if defined SEM_VALUE_MAX || _POSIX_SEM_VALUE_MAX
-#  define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1
-# endif
 #endif
 
 #include 


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 22/11/20 13:37 +, Jonathan Wakely via Libstdc++ wrote:

On Sun, 22 Nov 2020, 12:29 Iain Sandoe,  wrote:


thanks for looking at this over the weekend.

Jonathan Wakely via Gcc-patches  wrote:

> On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
>  wrote:
>> I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
>> fixes.  And a few c++ failures with similar symptoms.  I'm not certain
>> that it is due to this patch, but it's the likely suspect.
> Yes, it's that patch.
>
> This should fix most of those errors, but I haven't finished testing
> it, and can't commit it now anyway.
> 

with r11-5235 + this patch there are still quite a few fails on Darwin -
but
all seem to be the same ( so maybe only problem ;) ):
  “sem_timedwait was not declared in this scope”.

It looks like the semaphore header is optional in SUSv3 (AFAIK that’s still
the claimed edition for Darwin) - and although Darwin has the semaphore
header, it doesn’t seem to have an impl. of sem_timedwait.

just:
int sem_trywait(sem_t *);
int sem_wait(sem_t *) ;




It probably depends on the _POSIX_TIMEOUTS option which MacOS doesn't
support (optional in POSIX 2001, but not 2008).


Hopefully this fixes it, but I haven't tested it on darwin, only
linux, aix and solaris.

Committed.




Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 22/11/20 01:27 +, Jonathan Wakely via Libstdc++ wrote:

On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
 wrote:


I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
fixes.  And a few c++ failures with similar symptoms.  I'm not certain
that it is due to this patch, but it's the likely suspect.

Yes, it's that patch.

This should fix most of those errors, but I haven't finished testing
it, and can't commit it now anyway.


I've committed this now.

Tested powerpc64le-linux and (lightly) on powerpc-aix and
sparc-solaris.


commit 183ae52b226898cc34aa51d4153cf0c006212a8a
Author: Jonathan Wakely 
Date:   Sun Nov 22 01:00:46 2020

libstdc++: make atomic waiting depend on gthreads or futexes

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h: Do not define anything unless
gthreads or futexes are available.
* include/bits/atomic_timed_wait.h: Likewise.
* include/bits/semaphore_base.h: Likewise.
* include/std/semaphore: Likewise.
* include/bits/atomic_base.h (atomic_flag::wait)
(atomic_flag::notify_one, atomic_flag::notify_all)
(__atomic_base::wait, __atomic_base::notify_one)
(__atomic_base::notify_all, __atomic_base::wait)
(__atomic_base::notify_one, __atomic_base::notify_all)
(__atomic_impl::wait, __atomic_impl::notify_one)
(__atomic_impl::notify_all, __atomic_float::wait)
(__atomic_float::notify_one, __atomic_float::notify_all)
(__atomic_ref::wait, __atomic_ref::notify_one)
(__atomic_ref::notify_all): Only define if gthreads or futexes
are available.
* include/std/atomic (atomic::wait, atomic::notify_one)
(atomic::notify_all): Likewise.
* include/std/version (__cpp_lib_semaphore): Define
conditionally.

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 7de02f169977..d7db8612889e 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -230,6 +230,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL;
 }
 
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
 _GLIBCXX_ALWAYS_INLINE void
 wait(bool __old,
 	memory_order __m = memory_order_seq_cst) const noexcept
@@ -252,6 +253,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { std::__atomic_notify(&_M_i, true); }
 
 // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++20
 
 _GLIBCXX_ALWAYS_INLINE void
@@ -603,6 +605,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(__int_type __old,
 	  memory_order __m = memory_order_seq_cst) const noexcept
@@ -625,6 +628,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { std::__atomic_notify(&_M_i, true); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++2a
 
   _GLIBCXX_ALWAYS_INLINE __int_type
@@ -897,6 +901,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(__pointer_type __old,
 	   memory_order __m = memory_order_seq_cst) noexcept
@@ -919,6 +924,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { std::__atomic_notify(&_M_p, true); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++2a
 
   _GLIBCXX_ALWAYS_INLINE __pointer_type
@@ -1010,6 +1016,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
 template
   _GLIBCXX_ALWAYS_INLINE void
   wait(const _Tp* __ptr, _Val<_Tp> __old,
@@ -1034,6 +1041,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { std::__atomic_notify(__ptr, true); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++2a
 
 template
@@ -1289,6 +1297,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    __cmpexch_failure_order(__order));
   }
 
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(_Fp __old, memory_order __m = memory_order_seq_cst) const noexcept
   { __atomic_impl::wait(&_M_fp, __old, __m); }
@@ -1306,6 +1315,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { __atomic_impl::notify_all(&_M_fp); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 
   value_type
   fetch_add(value_type __i,
@@ -1444,6 +1454,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    __cmpexch_failure_order(__order));
   }
 
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(_Tp __old, 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 21/11/20 17:39 +, Jonathan Wakely wrote:

On 21/11/20 17:04 +, Jonathan Wakely wrote:

On 21/11/20 16:16 +0100, Andreas Schwab wrote:

In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
  from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
  from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
  from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
  from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')


I'm testing this.


I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test



Here's another small fix.

Tested powerpc64le-linux, pushed to trunk.



commit fd62daea40e09c1e6d599a6171db6b298d6c362e
Author: Jonathan Wakely 
Date:   Mon Nov 23 15:46:24 2020

libstdc++: Link tests to libatomic as required [PR 97948]

libstdc++-v3/ChangeLog:

PR libstdc++/97948
* testsuite/29_atomics/atomic_float/wait_notify.cc: Add options
for libatomic.
* testsuite/29_atomics/atomic_integral/wait_notify.cc: Likewise.
* testsuite/29_atomics/atomic_ref/wait_notify.cc: Likewise.

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 27d9b601c2f4..8f9e4a39a21f 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc
@@ -2,6 +2,7 @@
 // { dg-do run { target c++2a } }
 // { 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 6e9ee7dbf93f..abf2bfdbee96 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc
@@ -2,6 +2,7 @@
 // { dg-do run { target c++2a } }
 // { dg-require-effective-target pthread }
 // { dg-require-gthreads "" }
+// { dg-add-options libatomic }
 
 // Copyright (C) 2020 Free Software Foundation, Inc.
 //
diff --git 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-23 Thread Jonathan Wakely via Gcc-patches

On 21/11/20 16:36 -0800, H.J. Lu wrote:

On Sat, Nov 21, 2020 at 9:40 AM Jonathan Wakely via Gcc-patches
 wrote:


On 21/11/20 17:04 +, Jonathan Wakely wrote:
>On 21/11/20 16:16 +0100, Andreas Schwab wrote:
>>In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
>>from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) const':
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
>>In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
>>from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void std::__atomic_wait(const 
_Tp*, _Tp, _Pred)'
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
>>In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
>>from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
>>from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
>>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 'bool')
>
>I'm testing this.

I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test



I opened:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97936


Thanks.



Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-22 Thread Stephan Bergmann via Gcc-patches

On 20/11/2020 23:44, Thomas Rodgers wrote:

Tested x86_64-pc-linux-gnu, committed.


...and there are multiple definition complaints from the linker because 
of two missing "include":



index 7b2682a577e..23ab2018ca8 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -223,7 +223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { _M_w._M_do_wait(_M_version); }
 };
 
-void

+inline void
 __thread_relax() noexcept
 {
 #if defined __i386__ || defined __x86_64__
@@ -233,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 }
 
-void

+inline void
 __thread_yield() noexcept
{
 #if defined _GLIBCXX_USE_SCHED_YIELD




Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-22 Thread Stephan Bergmann via Gcc-patches

On 20/11/2020 23:44, Thomas Rodgers wrote:

Tested x86_64-pc-linux-gnu, committed.


Clang complains:


$ cat test.cc
#include 

$ clang++ --gcc-toolchain=~/gcc/trunk/inst -std=c++20 -fsyntax-only test.cc
In file included from test.cc:1:
In file included from 
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/semaphore:36:
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/bits/semaphore_base.h:145:22:
 error: no viable conversion from 'std::chrono::system_clock::time_point' (aka 
'time_point>>') 
to 'const std::__platform_semaphore::__clock_t' (aka 'const std::chrono::system_clock')
const __clock_t __s_entry = __clock_t::now();
^   
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/chrono:1101:12: 
note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 
'std::chrono::system_clock::time_point' (aka 'time_point>>') to 'const std::chrono::system_clock &' for 
1st argument
struct system_clock
   ^
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../include/c++/11.0.0/chrono:1101:12: note: 
candidate constructor (the implicit move constructor) not viable: no known conversion from 
'std::chrono::system_clock::time_point' (aka 'time_point>>') to 'std::chrono::system_clock &&' for 1st argument
1 error generated.


which


diff --git a/libstdc++-v3/include/bits/semaphore_base.h 
b/libstdc++-v3/include/bits/semaphore_base.h
index 78a0b6ba26e..f25c9fdb325 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -142,7 +142,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
else
  {
const typename _Clock::time_point __c_entry = _Clock::now();
-   const __clock_t __s_entry = __clock_t::now();
+   const __clock_t::time_point __s_entry = __clock_t::now();
const auto __delta = __atime - __c_entry;
const auto __s_atime = __s_entry + __delta;
if (_M_try_acquire_until_impl(__s_atime))
~


would fix.



Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-22 Thread Jonathan Wakely via Gcc-patches
On Sun, 22 Nov 2020, 12:29 Iain Sandoe,  wrote:

> thanks for looking at this over the weekend.
>
> Jonathan Wakely via Gcc-patches  wrote:
>
> > On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
> >  wrote:
> >> I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
> >> fixes.  And a few c++ failures with similar symptoms.  I'm not certain
> >> that it is due to this patch, but it's the likely suspect.
> > Yes, it's that patch.
> >
> > This should fix most of those errors, but I haven't finished testing
> > it, and can't commit it now anyway.
> > 
>
> with r11-5235 + this patch there are still quite a few fails on Darwin -
> but
> all seem to be the same ( so maybe only problem ;) ):
>   “sem_timedwait was not declared in this scope”.
>
> It looks like the semaphore header is optional in SUSv3 (AFAIK that’s still
> the claimed edition for Darwin) - and although Darwin has the semaphore
> header, it doesn’t seem to have an impl. of sem_timedwait.
>
> just:
> int sem_trywait(sem_t *);
> int sem_wait(sem_t *) ;
>


It probably depends on the _POSIX_TIMEOUTS option which MacOS doesn't
support (optional in POSIX 2001, but not 2008).


>
>


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-22 Thread Iain Sandoe via Gcc-patches

thanks for looking at this over the weekend.

Jonathan Wakely via Gcc-patches  wrote:


On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
 wrote:

I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
fixes.  And a few c++ failures with similar symptoms.  I'm not certain
that it is due to this patch, but it's the likely suspect.

Yes, it's that patch.

This should fix most of those errors, but I haven't finished testing
it, and can't commit it now anyway.



with r11-5235 + this patch there are still quite a few fails on Darwin - but
all seem to be the same ( so maybe only problem ;) ):
 “sem_timedwait was not declared in this scope”.

It looks like the semaphore header is optional in SUSv3 (AFAIK that’s still
the claimed edition for Darwin) - and although Darwin has the semaphore
header, it doesn’t seem to have an impl. of sem_timedwait.

just:
int sem_trywait(sem_t *);
int sem_wait(sem_t *) ;

thanks
Iain



Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-21 Thread Jonathan Wakely via Gcc-patches
On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
 wrote:
>
> I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
> fixes.  And a few c++ failures with similar symptoms.  I'm not certain
> that it is due to this patch, but it's the likely suspect.
Yes, it's that patch.

This should fix most of those errors, but I haven't finished testing
it, and can't commit it now anyway.
commit c304e59c2fd8c500232c4c88b632e051e481991f
Author: Jonathan Wakely 
Date:   Sun Nov 22 01:00:46 2020

libstdc++: make atomic waiting depend on gthreads or futexes

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h: Do not define anything unless
gthreads or futexes are available.
* include/bits/atomic_timed_wait.h: Likewise.
* include/bits/semaphore_base.h: Likewise.
* include/std/semaphore: Likewise.
* include/bits/atomic_base.h (atomic_flag::wait)
(atomic_flag::notify_one, atomic_flag::notify_all)
(__atomic_base::wait, __atomic_base::notify_one)
(__atomic_base::notify_all, __atomic_base::wait)
(__atomic_base::notify_one, __atomic_base::notify_all)
(__atomic_impl::wait, __atomic_impl::notify_one)
(__atomic_impl::notify_all, __atomic_float::wait)
(__atomic_float::notify_one, __atomic_float::notify_all)
(__atomic_ref::wait, __atomic_ref::notify_one)
(__atomic_ref::notify_all): Only define if gthreads or futexes
are available.
* include/std/atomic (atomic::wait, atomic::notify_one)
(atomic::notify_all): Likewise.

diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index 7de02f169977..d7db8612889e 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -230,6 +230,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL;
 }
 
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
 _GLIBCXX_ALWAYS_INLINE void
 wait(bool __old,
memory_order __m = memory_order_seq_cst) const noexcept
@@ -252,6 +253,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { std::__atomic_notify(&_M_i, true); }
 
 // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++20
 
 _GLIBCXX_ALWAYS_INLINE void
@@ -603,6 +605,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(__int_type __old,
  memory_order __m = memory_order_seq_cst) const noexcept
@@ -625,6 +628,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { std::__atomic_notify(&_M_i, true); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++2a
 
   _GLIBCXX_ALWAYS_INLINE __int_type
@@ -897,6 +901,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(__pointer_type __old,
   memory_order __m = memory_order_seq_cst) noexcept
@@ -919,6 +924,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { std::__atomic_notify(&_M_p, true); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++2a
 
   _GLIBCXX_ALWAYS_INLINE __pointer_type
@@ -1010,6 +1016,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
 template
   _GLIBCXX_ALWAYS_INLINE void
   wait(const _Tp* __ptr, _Val<_Tp> __old,
@@ -1034,6 +1041,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { std::__atomic_notify(__ptr, true); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 #endif // C++2a
 
 template
@@ -1289,6 +1297,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __cmpexch_failure_order(__order));
   }
 
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(_Fp __old, memory_order __m = memory_order_seq_cst) const noexcept
   { __atomic_impl::wait(&_M_fp, __old, __m); }
@@ -1306,6 +1315,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { __atomic_impl::notify_all(&_M_fp); }
 
   // TODO add const volatile overload
+#endif // GTHREADS || LINUX_FUTEX
 
   value_type
   fetch_add(value_type __i,
@@ -1444,6 +1454,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __cmpexch_failure_order(__order));
   }
 
+#if defined _GLIBCXX_HAS_GTHREADS || _GLIBCXX_HAVE_LINUX_FUTEX
   _GLIBCXX_ALWAYS_INLINE void
   wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
   { __atomic_impl::wait(_M_ptr, __old, __m); }
@@ -1461,6 +1472,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-21 Thread H.J. Lu via Gcc-patches
On Sat, Nov 21, 2020 at 9:40 AM Jonathan Wakely via Gcc-patches
 wrote:
>
> On 21/11/20 17:04 +, Jonathan Wakely wrote:
> >On 21/11/20 16:16 +0100, Andreas Schwab wrote:
> >>In file included from 
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
> >> In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
> >>const':
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
> >> error: no matching function for call to '__atomic_wait(const 
> >>__atomic_flag_data_type*, bool&, std::atomic_flag::wait(bool, 
> >>std::memory_order) const::)'
> >>In file included from 
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
> >> note: candidate: 'template void 
> >>std::__atomic_wait(const _Tp*, _Tp, _Pred)'
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
> >> note:   template argument deduction/substitution failed:
> >>In file included from 
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
> >>from 
> >> /daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
> >>/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
> >> note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
> >>'bool')
> >
> >I'm testing this.
>
> I'm committing this instead, it's the same but also disables
> 29_atomics/atomic/wait_notify/generic.cc on non-linux targets.
>
> Tested sparc-solaris2.11 and powerpc64le-linux.
>
> There are still some timeouts on linux:
>
> FAIL: 30_threads/latch/3.cc execution test
> FAIL: 30_threads/semaphore/try_acquire_for.cc execution test
>

I opened:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97936

-- 
H.J.


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-21 Thread David Edelsohn via Gcc-patches
I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
fixes.  And a few c++ failures with similar symptoms.  I'm not certain
that it is due to this patch, but it's the likely suspect.

FAIL: 17_intro/headers/c++2020/all_attributes.cc (test for excess errors)
FAIL: 17_intro/headers/c++2020/all_no_exceptions.cc (test for excess errors)
FAIL: 17_intro/headers/c++2020/all_no_rtti.cc (test for excess errors)
FAIL: 17_intro/headers/c++2020/all_pedantic_errors.cc (test for excess errors)
FAIL: 17_intro/headers/c++2020/operator_names.cc (test for excess errors)
FAIL: 17_intro/headers/c++2020/stdc++.cc (test for excess errors)
FAIL: 17_intro/headers/c++2020/stdc++_multiple_inclusion.cc (test for
excess errors)
FAIL: 20_util/allocator/rebind_c++20.cc (test for excess errors)
FAIL: 20_util/allocator/requirements/constexpr.cc (test for excess errors)
FAIL: 20_util/allocator/requirements/typedefs_c++20.cc (test for excess errors)
FAIL: 20_util/allocator_traits/header.cc (test for excess errors)
FAIL: 20_util/allocator_traits/members/92878_92947.cc (test for excess errors)
UNRESOLVED: 20_util/allocator_traits/members/92878_92947.cc
compilation failed to produce executable
FAIL: 20_util/assume_aligned/1.cc (test for excess errors)
UNRESOLVED: 20_util/assume_aligned/1.cc compilation failed to produce executable
FAIL: 20_util/assume_aligned/2_neg.cc (test for excess errors)
FAIL: 20_util/assume_aligned/3.cc (test for excess errors)
UNRESOLVED: 20_util/assume_aligned/3.cc scan-assembler-not undefined
FAIL: 20_util/assume_aligned/97132.cc (test for excess errors)
FAIL: 20_util/function_objects/bind_front/2.cc (test for excess errors)
UNRESOLVED: 20_util/function_objects/bind_front/2.cc compilation
failed to produce executable
FAIL: 20_util/pair/comparison_operators/constexpr_c++20.cc (test for
excess errors)
FAIL: 20_util/pair/cons/92878_92947.cc (test for excess errors)
UNRESOLVED: 20_util/pair/cons/92878_92947.cc compilation failed to
produce executable
etc.

The errors all are of the form:

/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:125:
error: 'mutex' is not a member of 'std'
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:125:
error: template argument 1 is invalid
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:125:
error: '' in namespace 'std' does not name a type
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:126:
error: '__lock_t' does not name a type; did you mean 'clock_t'?
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:132:
error: '__gthread_cond_t' does not name a type; did you mean
'pthread_cond_t'?
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:135:
error: '_M_cond' was not declared in this scope
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:135:
error: '__GTHREAD_COND_INIT_FUNCTION' was not declared in this scope
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:164:
error: '__lock_t' is not a member of 'std::__detail::__waiters'
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:165:
error: '_M_cv' was not declared in this scope
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:165:
error: '__l' was not declared in this scope; did you mean '__lg'?
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:165:
error: '__gthread_cond_wait' was not declared in this scope; did you
mean 'pthread_cond_t'?
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:191:
error: '_M_cv' was not declared in this scope
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/bits/atomic_wait.h:191:
error: '__gthread_cond_broadcast' was not declared in this scope
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++v3/include/bits/atomic_timed_wait.h:144:
error: '__gthread_cond_t' was not declared in this scope; did you mean
'pthread_cond_t'?
/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++v3/include/bits/atomic_timed_wait.h:144:
error: '__cv' was not declared in this scope


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-21 Thread Jonathan Wakely via Gcc-patches

On 21/11/20 17:04 +, Jonathan Wakely wrote:

On 21/11/20 16:16 +0100, Andreas Schwab wrote:

In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
   from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
   from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
   from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
   from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')


I'm testing this.


I'm committing this instead, it's the same but also disables
29_atomics/atomic/wait_notify/generic.cc on non-linux targets.

Tested sparc-solaris2.11 and powerpc64le-linux.

There are still some timeouts on linux:

FAIL: 30_threads/latch/3.cc execution test
FAIL: 30_threads/semaphore/try_acquire_for.cc execution test


commit 6f5387b7c9047baa5ee1385c8f5148d2c351bd20
Author: Jonathan Wakely 
Date:   Sat Nov 21 16:52:22 2020

libstdc++: Fix atomic waiting for non-linux targets

This fixes some UNRESOLVED tests on (at least) Solaris and Darwin, and
disables some tests that hang forever on Solaris. A proper fix is still
needed.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (atomic_flag::wait): Use correct
type for __atomic_wait call.
* include/bits/atomic_timed_wait.h (__atomic_wait_until): Check
_GLIBCXX_HAVE_LINUX_FUTEX.
* include/bits/atomic_wait.h (__atomic_notify): Likewise.
* include/bits/semaphore_base.h (_GLIBCXX_HAVE_POSIX_SEMAPHORE):
Only define if SEM_VALUE_MAX or _POSIX_SEM_VALUE_MAX is defined.
* testsuite/29_atomics/atomic/wait_notify/bool.cc: Disable on
non-linux targes.
* 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.

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index dd4db926592e..7de02f169977 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -234,7 +234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 wait(bool __old,
 	memory_order __m = memory_order_seq_cst) const noexcept
 {
-  std::__atomic_wait(&_M_i, __old,
+  std::__atomic_wait(&_M_i, static_cast<__atomic_flag_data_type>(__old),
 			 [__m, this, __old]()
 			 { return this->test(__m) != 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-21 Thread Jonathan Wakely via Gcc-patches

On 21/11/20 16:16 +0100, Andreas Schwab wrote:

In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const __atomic_flag_data_type*, 
bool&, std::atomic_flag::wait(bool, std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')


I'm testing this.


commit 613ac97bed57eb0edb1803b66d5ce3510e665b3d
Author: Jonathan Wakely 
Date:   Sat Nov 21 16:52:22 2020

libstdc++: Fix atomic waiting for non-linux targets

This fixes some UNRESOLVED tests on (at least) Solaris and Darwin, and
disables some tests that hang forever on Solaris. A proper fix is still
needed.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (atomic_flag::wait): Use correct
type for __atomic_wait call.
* include/bits/atomic_timed_wait.h (__atomic_wait_until): Check
_GLIBCXX_HAVE_LINUX_FUTEX.
* include/bits/atomic_wait.h (__atomic_notify): Likewise.
* include/bits/semaphore_base.h (_GLIBCXX_HAVE_POSIX_SEMAPHORE):
Only define if SEM_VALUE_MAX or _POSIX_SEM_VALUE_MAX is defined.
* testsuite/29_atomics/atomic/wait_notify/bool.cc: Disable on
non-linux targes.
* 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.

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index dd4db926592e..7de02f169977 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -234,7 +234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 wait(bool __old,
 	memory_order __m = memory_order_seq_cst) const noexcept
 {
-  std::__atomic_wait(&_M_i, __old,
+  std::__atomic_wait(&_M_i, static_cast<__atomic_flag_data_type>(__old),
 			 [__m, this, __old]()
 			 { return this->test(__m) != __old; });
 }
diff --git a/libstdc++-v3/include/bits/atomic_timed_wait.h b/libstdc++-v3/include/bits/atomic_timed_wait.h
index 7712a6c591dc..405f7e93ca85 100644
--- a/libstdc++-v3/include/bits/atomic_timed_wait.h
+++ b/libstdc++-v3/include/bits/atomic_timed_wait.h
@@ -240,12 +240,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   do
 	{
 	  __atomic_wait_status __res;
+#ifdef _GLIBCXX_HAVE_LINUX_FUTEX
 	  if constexpr 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-21 Thread Andreas Schwab
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
 from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:
 In member function 'void std::atomic_flag::wait(bool, std::memory_order) 
const':
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 error: no matching function for call to '__atomic_wait(const 
__atomic_flag_data_type*, bool&, std::atomic_flag::wait(bool, 
std::memory_order) const::)'
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:41,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
 from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note: candidate: 'template void 
std::__atomic_wait(const _Tp*, _Tp, _Pred)'
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_wait.h:265:
 note:   template argument deduction/substitution failed:
In file included from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/memory:78,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/stdc++.h:82,
 from 
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/m68k-linux/bits/extc++.h:32,
 from 
/daten/aranym/gcc/gcc-20201121/libstdc++-v3/testsuite/17_intro/headers/c++2020/all_attributes.cc:37:
/daten/aranym/gcc/gcc-20201121/Build/m68k-linux/libstdc++-v3/include/bits/atomic_base.h:239:
 note:   deduced conflicting types for parameter '_Tp' ('unsigned char' and 
'bool')

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-11-20 Thread Thomas Rodgers
Tested x86_64-pc-linux-gnu, committed.

> On Oct 27, 2020, at 3:23 AM, Jonathan Wakely  wrote:
> 
> On 26/10/20 14:48 -0700, Thomas Rodgers wrote:
>> +#include 
>> +
>> +#if __has_include()
>> +#define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1
>> +#include 
> 
> It occurs to me now that this check probably isn't robust enough. For
> any POSIX system it's probably safe to assume that  means
> the POSIX header and so sem_t is available.
> 
> But on non-POSIX systems there could be some other, unrelated header
> called  in the include paths that the user is compiling
> this header with. It's not inconceivable that the user's own project
> or some third party lib could provide a file called semaphore.h, which
> wouldn't define sem_t, sem_init etc.
> 
> It's OK for now, but we should revisit this and add an autoconf check
> for sem_init etc. to check at build time whether we've got POSIX
> semaphores available or not.
> 
> Please add a "FIXME: replace this with an autoconf check" comment
> here.
> 
> OK for trunk with that change, thanks.
> 



Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-10-27 Thread Jonathan Wakely via Gcc-patches

On 26/10/20 14:48 -0700, Thomas Rodgers wrote:

+#include 
+
+#if __has_include()
+#define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1
+#include 


It occurs to me now that this check probably isn't robust enough. For
any POSIX system it's probably safe to assume that  means
the POSIX header and so sem_t is available.

But on non-POSIX systems there could be some other, unrelated header
called  in the include paths that the user is compiling
this header with. It's not inconceivable that the user's own project
or some third party lib could provide a file called semaphore.h, which
wouldn't define sem_t, sem_init etc.

It's OK for now, but we should revisit this and add an autoconf check
for sem_init etc. to check at build time whether we've got POSIX
semaphores available or not.

Please add a "FIXME: replace this with an autoconf check" comment
here.

OK for trunk with that change, thanks.



[PATCH] libstdc++: Add C++2a synchronization support

2020-10-26 Thread Thomas Rodgers
From: Thomas Rodgers 

Add support for -
  * atomic_flag::wait/notify_one/notify_all
  * atomic::wait/notify_one/notify_all
  * counting_semaphore
  * binary_semaphore
  * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise.
* testsuite/29_atomic/atomic_float/wait_notify.cc: Likewise.
* testsuite/29_atomic/atomic_integral/wait_notify.cc: Likewise.
* testsuite/29_atomic/atomic_ref/wait_notify.cc: Likewise.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
* testsuite/util/atomic/wait_notify_util.h: New File.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 195 ++-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 287 
 libstdc++-v3/include/bits/atomic_wait.h   | 306 ++
 libstdc++-v3/include/bits/semaphore_base.h| 296 +
 libstdc++-v3/include/std/atomic   |  78 +
 libstdc++-v3/include/std/latch|  91 ++
 libstdc++-v3/include/std/semaphore|  92 ++
 libstdc++-v3/include/std/version  |   2 +
 .../29_atomics/atomic/wait_notify/bool.cc |  59 
 .../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 .../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
 .../29_atomics/atomic_float/wait_notify.cc|  32 ++
 .../29_atomics/atomic_integral/wait_notify.cc |  65 
 .../29_atomics/atomic_ref/wait_notify.cc  | 103 ++
 libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/3.cc  |  69 
 .../testsuite/30_threads/semaphore/1.cc   |  27 ++
 .../testsuite/30_threads/semaphore/2.cc   |  27 ++
 .../semaphore/least_max_value_neg.cc  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_posix.cc | 153 +
 .../30_threads/semaphore/try_acquire_until.cc |  94 ++
 .../testsuite/util/atomic/wait_notify_util.h  | 160 +
 28 files changed, 2520 insertions(+), 1 deletion(-)
 

[PATCH] libstdc++: Add C++2a synchronization support

2020-10-02 Thread Thomas Rodgers
From: Thomas Rodgers 

Updated patch incorporating latest feedback (revised).

Add support for -
  * atomic_flag::wait/notify_one/notify_all
  * atomic::wait/notify_one/notify_all
  * counting_semaphore
  * binary_semaphore
  * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
 libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
 libstdc++-v3/include/bits/semaphore_base.h| 283 
 libstdc++-v3/include/std/atomic   |  73 +
 libstdc++-v3/include/std/latch|  90 ++
 libstdc++-v3/include/std/semaphore|  92 ++
 libstdc++-v3/include/std/version  |   2 +
 .../atomic/wait_notify/atomic_refs.cc | 103 ++
 .../29_atomics/atomic/wait_notify/bool.cc |  59 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
 .../29_atomics/atomic/wait_notify/generic.h   | 160 ++
 .../atomic/wait_notify/integrals.cc   |  65 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 .../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
 libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
 .../testsuite/30_threads/semaphore/1.cc   |  27 ++
 .../testsuite/30_threads/semaphore/2.cc   |  27 ++
 .../semaphore/least_max_value_neg.cc  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_posix.cc | 153 +
 

[PATCH] libstdc++: Add C++2a synchronization support

2020-10-01 Thread Thomas Rodgers
From: Thomas Rodgers 

Updated patch incorporating latest feedback.

Add support for -
  * atomic_flag::wait/notify_one/notify_all
  * atomic::wait/notify_one/notify_all
  * counting_semaphore
  * binary_semaphore
  * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
 libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
 libstdc++-v3/include/bits/semaphore_base.h| 283 
 libstdc++-v3/include/std/atomic   |  73 +
 libstdc++-v3/include/std/latch|  90 ++
 libstdc++-v3/include/std/semaphore|  92 ++
 libstdc++-v3/include/std/version  |   2 +
 .../atomic/wait_notify/atomic_refs.cc | 103 ++
 .../29_atomics/atomic/wait_notify/bool.cc |  59 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
 .../29_atomics/atomic/wait_notify/generic.h   | 160 ++
 .../atomic/wait_notify/integrals.cc   |  65 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 .../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
 libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
 .../testsuite/30_threads/semaphore/1.cc   |  27 ++
 .../testsuite/30_threads/semaphore/2.cc   |  27 ++
 .../semaphore/least_max_value_neg.cc  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_posix.cc | 153 +
 .../30_threads/semaphore/try_acquire_until.cc |  94 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-09-29 Thread Jonathan Wakely via Gcc-patches

On 28/09/20 14:29 -0700, Thomas Rodgers wrote:

+template
+  __atomic_wait_status
+  __platform_wait_until_impl(__platform_wait_t* __addr,
+__platform_wait_t __val,
+const 
chrono::time_point<__platform_wait_clock_t,
+ _Duration>& __atime) 
noexcept
+  {
+   auto __s = chrono::time_point_cast(__atime);
+   auto __ns = chrono::duration_cast(__atime - __s);
+
+   struct timespec __rt =
+   {
+ static_cast(__s.time_since_epoch().count()),
+ static_cast(__ns.count())
+   };
+
+   auto __e = syscall (SYS_futex, __addr,
+ 
static_cast(__futex_wait_flags::__wait_bitset_private),
+ __val, &__rt, nullptr,
+ 
static_cast(__futex_wait_flags::__bitset_match_any));
+   if (__e && !(errno == EINTR || errno == EAGAIN || errno == ETIMEDOUT))
+   std::terminate();
+   return (__platform_wait_clock_t::now() < __atime)
+  ? __atomic_wait_status::no_timeout : 
__atomic_wait_status::timeout;
+  }
+
+template
+  __atomic_wait_status
+  __platform_wait_until(__platform_wait_t* __addr, __platform_wait_t __val,
+   const chrono::time_point<_Clock, _Duration>& 
__atime)
+  {
+   if constexpr (is_same_v<__platform_wait_clock_t, _Clock>)


This case is impossible, since the other overload would be selected
if the clock is the __platform_wait_clock_t (unless the caller says
__platform_wait_until<__platform_wait_until> to explicitly call this
overload, but users can't call this function, and we won't do that).



Which overload?



I must have misread __platform_wait_until_impl above as
__platform_wait_until. Ignore this comment, sorry!




Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-09-28 Thread Thomas Rodgers via Gcc-patches


Jonathan Wakely writes:

> On 11/09/20 16:58 -0700, Thomas Rodgers wrote:
>>From: Thomas Rodgers 
>>
>>This patch supercedes both the Add C++2a synchronization support patch
>>being replied to *and* the patch adding wait/notify_* to atomic_flag.
>>
>>Add support for -
>>  * atomic_flag::wait/notify_one/notify_all
>>  * atomic::wait/notify_one/notify_all
>>  * counting_semaphore
>>  * binary_semaphore
>>  * latch
>>
>>libstdc++-v3/ChangeLog:
>>
>>  * include/Makefile.am (bits_headers): Add new header.
>>  * include/Makefile.in: Regenerate.
>>  * include/bits/atomic_base.h (__atomic_flag::wait): Define.
>>  (__atomic_flag::notify_one): Likewise.
>>  (__atomic_flag::notify_all): Likewise.
>>  (__atomic_base<_Itp>::wait): Likewise.
>>  (__atomic_base<_Itp>::notify_one): Likewise.
>>  (__atomic_base<_Itp>::notify_all): Likewise.
>>  (__atomic_base<_Ptp*>::wait): Likewise.
>>  (__atomic_base<_Ptp*>::notify_one): Likewise.
>>  (__atomic_base<_Ptp*>::notify_all): Likewise.
>>  (__atomic_impl::wait): Likewise.
>>  (__atomic_impl::notify_one): Likewise.
>>  (__atomic_impl::notify_all): Likewise.
>>  (__atomic_float<_Fp>::wait): Likewise.
>>  (__atomic_float<_Fp>::notify_one): Likewise.
>>  (__atomic_float<_Fp>::notify_all): Likewise.
>>  (__atomic_ref<_Tp>::wait): Likewise.
>>  (__atomic_ref<_Tp>::notify_one): Likewise.
>>  (__atomic_ref<_Tp>::notify_all): Likewise.
>>  (atomic_wait<_Tp>): Likewise.
>>  (atomic_wait_explicit<_Tp>): Likewise.
>>  (atomic_notify_one<_Tp>): Likewise.
>>  (atomic_notify_all<_Tp>): Likewise.
>>  * include/bits/atomic_wait.h: New file.
>>  * include/bits/atomic_timed_wait.h: New file.
>>  * include/bits/semaphore_base.h: New file.
>>  * include/std/atomic (atomic::wait): Define.
>>  (atomic::wait_one): Likewise.
>>  (atomic::wait_all): Likewise.
>>  (atomic<_Tp>::wait): Likewise.
>>  (atomic<_Tp>::wait_one): Likewise.
>>  (atomic<_Tp>::wait_all): Likewise.
>>  (atomic<_Tp*>::wait): Likewise.
>>  (atomic<_Tp*>::wait_one): Likewise.
>>  (atomic<_Tp*>::wait_all): Likewise.
>>  * include/std/latch: New file.
>>  * include/std/semaphore: New file.
>>  * include/std/version: Add __cpp_lib_semaphore and
>>  __cpp_lib_latch defines.
>>  * testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
>>  * testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
>>  * testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
>>  * testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
>>  * testsuite/30_thread/semaphore/1.cc: New test.
>>  * testsuite/30_thread/semaphore/2.cc: Likewise.
>>  * testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
>>  * testsuite/30_thread/latch/1.cc: New test.
>>  * testsuite/30_thread/latch/2.cc: New test.
>>  * testsuite/30_thread/latch/3.cc: New test.
>>---
>> libstdc++-v3/include/Makefile.am  |   5 +
>> libstdc++-v3/include/Makefile.in  |   5 +
>> libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
>> libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
>> libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
>> libstdc++-v3/include/bits/semaphore_base.h| 283 
>> libstdc++-v3/include/std/atomic   |  73 +
>> libstdc++-v3/include/std/latch|  90 ++
>> libstdc++-v3/include/std/semaphore|  92 ++
>> libstdc++-v3/include/std/version  |   2 +
>> .../atomic/wait_notify/atomic_refs.cc | 103 ++
>> .../29_atomics/atomic/wait_notify/bool.cc |  59 
>> .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
>> .../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
>> .../29_atomics/atomic/wait_notify/generic.h   | 160 ++
>> .../atomic/wait_notify/integrals.cc   |  65 
>> .../29_atomics/atomic/wait_notify/pointers.cc |  59 
>> .../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
>> libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
>> libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
>> libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
>> .../testsuite/30_threads/semaphore/1.cc   |  27 ++
>> .../testsuite/30_threads/semaphore/2.cc   |  27 ++
>> .../semaphore/least_max_value_neg.cc  

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-09-28 Thread Jonathan Wakely via Gcc-patches

On 11/09/20 16:58 -0700, Thomas Rodgers wrote:

From: Thomas Rodgers 

This patch supercedes both the Add C++2a synchronization support patch
being replied to *and* the patch adding wait/notify_* to atomic_flag.

Add support for -
 * atomic_flag::wait/notify_one/notify_all
 * atomic::wait/notify_one/notify_all
 * counting_semaphore
 * binary_semaphore
 * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
libstdc++-v3/include/Makefile.am  |   5 +
libstdc++-v3/include/Makefile.in  |   5 +
libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
libstdc++-v3/include/bits/semaphore_base.h| 283 
libstdc++-v3/include/std/atomic   |  73 +
libstdc++-v3/include/std/latch|  90 ++
libstdc++-v3/include/std/semaphore|  92 ++
libstdc++-v3/include/std/version  |   2 +
.../atomic/wait_notify/atomic_refs.cc | 103 ++
.../29_atomics/atomic/wait_notify/bool.cc |  59 
.../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
.../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
.../29_atomics/atomic/wait_notify/generic.h   | 160 ++
.../atomic/wait_notify/integrals.cc   |  65 
.../29_atomics/atomic/wait_notify/pointers.cc |  59 
.../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
.../testsuite/30_threads/semaphore/1.cc   |  27 ++
.../testsuite/30_threads/semaphore/2.cc   |  27 ++
.../semaphore/least_max_value_neg.cc  |  30 ++
.../30_threads/semaphore/try_acquire.cc   |  55 
.../30_threads/semaphore/try_acquire_for.cc   |  85 +

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-09-28 Thread Jonathan Wakely via Gcc-patches

On 11/09/20 16:58 -0700, Thomas Rodgers wrote:

From: Thomas Rodgers 

This patch supercedes both the Add C++2a synchronization support patch
being replied to *and* the patch adding wait/notify_* to atomic_flag.

Add support for -
 * atomic_flag::wait/notify_one/notify_all
 * atomic::wait/notify_one/notify_all
 * counting_semaphore
 * binary_semaphore
 * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
libstdc++-v3/include/Makefile.am  |   5 +
libstdc++-v3/include/Makefile.in  |   5 +
libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
libstdc++-v3/include/bits/semaphore_base.h| 283 
libstdc++-v3/include/std/atomic   |  73 +
libstdc++-v3/include/std/latch|  90 ++
libstdc++-v3/include/std/semaphore|  92 ++
libstdc++-v3/include/std/version  |   2 +
.../atomic/wait_notify/atomic_refs.cc | 103 ++
.../29_atomics/atomic/wait_notify/bool.cc |  59 
.../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
.../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
.../29_atomics/atomic/wait_notify/generic.h   | 160 ++
.../atomic/wait_notify/integrals.cc   |  65 
.../29_atomics/atomic/wait_notify/pointers.cc |  59 
.../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
.../testsuite/30_threads/semaphore/1.cc   |  27 ++
.../testsuite/30_threads/semaphore/2.cc   |  27 ++
.../semaphore/least_max_value_neg.cc  |  30 ++
.../30_threads/semaphore/try_acquire.cc   |  55 
.../30_threads/semaphore/try_acquire_for.cc   |  85 +

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-09-28 Thread Jonathan Wakely via Gcc-patches

On 11/09/20 16:58 -0700, Thomas Rodgers wrote:

From: Thomas Rodgers 

This patch supercedes both the Add C++2a synchronization support patch
being replied to *and* the patch adding wait/notify_* to atomic_flag.

Add support for -
 * atomic_flag::wait/notify_one/notify_all
 * atomic::wait/notify_one/notify_all
 * counting_semaphore
 * binary_semaphore
 * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
libstdc++-v3/include/Makefile.am  |   5 +
libstdc++-v3/include/Makefile.in  |   5 +
libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
libstdc++-v3/include/bits/semaphore_base.h| 283 
libstdc++-v3/include/std/atomic   |  73 +
libstdc++-v3/include/std/latch|  90 ++
libstdc++-v3/include/std/semaphore|  92 ++
libstdc++-v3/include/std/version  |   2 +
.../atomic/wait_notify/atomic_refs.cc | 103 ++
.../29_atomics/atomic/wait_notify/bool.cc |  59 
.../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
.../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
.../29_atomics/atomic/wait_notify/generic.h   | 160 ++
.../atomic/wait_notify/integrals.cc   |  65 
.../29_atomics/atomic/wait_notify/pointers.cc |  59 
.../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
.../testsuite/30_threads/semaphore/1.cc   |  27 ++
.../testsuite/30_threads/semaphore/2.cc   |  27 ++
.../semaphore/least_max_value_neg.cc  |  30 ++
.../30_threads/semaphore/try_acquire.cc   |  55 
.../30_threads/semaphore/try_acquire_for.cc   |  85 +

[PATCH] libstdc++: Add C++2a synchronization support

2020-09-11 Thread Thomas Rodgers
From: Thomas Rodgers 

This patch supercedes both the Add C++2a synchronization support patch
being replied to *and* the patch adding wait/notify_* to atomic_flag.

Add support for -
  * atomic_flag::wait/notify_one/notify_all
  * atomic::wait/notify_one/notify_all
  * counting_semaphore
  * binary_semaphore
  * latch

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
(__atomic_base<_Itp>::wait): Likewise.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
 libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
 libstdc++-v3/include/bits/semaphore_base.h| 283 
 libstdc++-v3/include/std/atomic   |  73 +
 libstdc++-v3/include/std/latch|  90 ++
 libstdc++-v3/include/std/semaphore|  92 ++
 libstdc++-v3/include/std/version  |   2 +
 .../atomic/wait_notify/atomic_refs.cc | 103 ++
 .../29_atomics/atomic/wait_notify/bool.cc |  59 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
 .../29_atomics/atomic/wait_notify/generic.h   | 160 ++
 .../atomic/wait_notify/integrals.cc   |  65 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 .../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
 libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
 .../testsuite/30_threads/semaphore/1.cc   |  27 ++
 .../testsuite/30_threads/semaphore/2.cc   |  27 ++
 .../semaphore/least_max_value_neg.cc  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +