libstdc++: '_GLIBCXX_HAS_GTHREADS' -- '__GTHREADS' vs. '__GTHREADS_CXX0X'

Jonathan Wakely jwakely@redhat.com
Thu Feb 20 12:48:23 GMT 2025


On Thu, 20 Feb 2025 at 12:29, Thomas Schwinge <tschwinge@baylibre.com> wrote:
>
> Hi!
>
> I'm still working on libstdc++ support for GCC's GPU targets: GCN, nvptx.
> These configurations are (in typical use) multi-threaded, and support
> mutexes etc., but they don't support dynamic spawning of threads etc.
> Therefore, re 'libgcc/gthr.h', they define '__GTHREADS' but *not*
> '__GTHREADS_CXX0X'.  (See 'libgcc/config/gcn/gthr-gcn.h'; nvptx still to
> be done, currently 'Thread model: single', very likely bogus...)
>
> Now, 'libstdc++-v3/acinclude.m4:GLIBCXX_CHECK_GTHREADS' does:
>
>     [...]
>       AC_MSG_CHECKING([for gthreads library])
>
>       AC_TRY_COMPILE([#include "gthr.h"],
>         [
>           #ifndef __GTHREADS_CXX0X
>           #error
>           #endif
>         ], [ac_has_gthreads=yes], [ac_has_gthreads=no])
>       else
>         ac_has_gthreads=no
>       fi
>
>       AC_MSG_RESULT([$ac_has_gthreads])
>
>       if test x"$ac_has_gthreads" = x"yes"; then
>         AC_DEFINE(_GLIBCXX_HAS_GTHREADS, 1,
>                   [Define if gthreads library is available.])
>     [...]
>
> That is, it defines '_GLIBCXX_HAS_GTHREADS' per '__GTHREADS_CXX0X'.
> Dependent on this '_GLIBCXX_HAS_GTHREADS',
> 'libstdc++-v3/include/bits/std_mutex.h' then enables 'class mutex'.  In
> other words, in the current GCN configuration ('__GTHREADS', but not
> '__GTHREADS_CXX0X'), 'class mutex' (and probably more) is not available,
> which leads to build issues (and presumably a lot of noise in the test
> suite).
>
> Is '__GTHREADS != __GTHREADS_CXX0X' simply a configuration that libstdc++
> so far has not attempted to support?

Yes. __GTHREADS is the original macro, which means "there is support
for some gthreads functions like __gthread_mutex_lock".

For the C++11 <thread>, <mutex>, and <condition_variable> headers the
new __GTHREADS_CXX0X macro was defined to mean "there is support for
everything needed by C++11". There are significant extra requirements
that __GTHREADS does not guarantee.

>  To make that work, do we need to
> consider '__GTHREADS' vs. '__GTHREADS_CXX0X' individually in libstdc++,
> for guarding the respective features?

Yes, and maybe __GTHREAD_HAS_COND too.

Based on the comments in gthr.h I think __GTHREADS is sufficient for std::mutex.

But __GTHREADS_CXX0X is needed for std::timed_mutex,
std::recursive_mutex, and  std::recursive_timed_mutex, and for
std::thread and std::condition_variable. I don't think it will be
easy, or worthwhile, to try and enable those without full
__GTHREADS_CXX0X support.



More information about the Libstdc++ mailing list