On Wed, Apr 21, 2021 at 3:16 PM Jakub Jelinek <ja...@redhat.com> wrote: > > On Wed, Apr 21, 2021 at 08:28:55PM +0200, Jakub Jelinek via Gcc-patches wrote: > > > There's a patch attempt for the problem with > > > std::thread::hardware_concurrency where > > > it's used only if _GLIBCXX_HAS_GTHREADS is set. > > > > > > Does it help? > > > Thanks, > > > Martin > > > > > > gcc/ChangeLog: > > > > > > PR bootstrap/100186 > > > * lto-wrapper.c: Use hardware_concurrency only if > > > _GLIBCXX_HAS_GTHREADS. > > > --- > > > gcc/lto-wrapper.c | 6 +++++- > > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > > > diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c > > > index 6ba401007f6..8a85b3e93a8 100644 > > > --- a/gcc/lto-wrapper.c > > > +++ b/gcc/lto-wrapper.c > > > @@ -1285,7 +1285,11 @@ run_gcc (unsigned argc, char *argv[]) > > > static char current_dir[] = { '.', DIR_SEPARATOR, '\0' }; > > > > > > /* Number of CPUs that can be used for parallel LTRANS phase. */ > > > - unsigned long nthreads_var = std::thread::hardware_concurrency (); > > > + unsigned long nthreads_var = 0; > > > + > > > +#ifdef _GLIBCXX_HAS_GTHREADS > > > + nthreads_var = std::thread::hardware_concurrency (); > > > +#endif > > > > _GLIBCXX_HAS_GTHREADS is a libstdc++ internal macro, it shouldn't be used > > outside of libstdc++. > > And, when using some other compiler or standard C++ library, nthreads_var > > will be always 0. That isn't an improvement. > > What would be IMHO a good idea would be to use configure test for > #include <thread> > int t = std::thread::hardware_concurrency (); > and in that case use that as a fallback to the previous implementation, > that will be strictly an improvement.
Would it be good enough to add a compile-time test for GCC VERSION >= 10 and fallback to the value 1 otherwise? If one performs the recommended bootstrap of the compiler, stage2 and stage3 will pick up <thread> from the newly built libstdc++ that always defines std::thread and will provide the expected feature. The problem is the stage1 compiler that may be built with an older compiler or building GCC without performing a three-stage bootstrap. Thanks, David