Ignore system_error in thread startup
authorTom Tromey <tromey@adacore.com>
Fri, 20 Nov 2020 15:22:46 +0000 (08:22 -0700)
committerTom Tromey <tromey@adacore.com>
Fri, 20 Nov 2020 15:22:46 +0000 (08:22 -0700)
libstdc++ might change so that it always implements std::thread, but
then have thread startup simply fail.  This is being discussed here:

https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558736.html

This patch pre-emptively changes gdb to handle this scenario.  It
seemed fine to me to ignore all system errors at thread startup, so
that is what this does.

gdbsupport/ChangeLog
2020-11-20  Tom Tromey  <tromey@adacore.com>

* thread-pool.cc (thread_pool::set_thread_count): Ignore system
errors.

gdbsupport/ChangeLog
gdbsupport/thread-pool.cc

index 2e5b3fa8004808051019dc9ee4d25e43c4d066a7..d1e46a3dca8eb7a34b4bf6d0963ca04f3b3b43d6 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-20  Tom Tromey  <tromey@adacore.com>
+
+       * thread-pool.cc (thread_pool::set_thread_count): Ignore system
+       errors.
+
 2020-11-10  Tom Tromey  <tromey@adacore.com>
 
        PR build/26848:
index be9ca22682a0bf59e13bd8bf8098be09cc2487ae..06586f7da0304b39b13ff1cdcb22c497ad01c551 100644 (file)
@@ -25,6 +25,7 @@
 #include "gdbsupport/alt-stack.h"
 #include "gdbsupport/block-signals.h"
 #include <algorithm>
+#include <system_error>
 
 /* On the off chance that we have the pthread library on a Windows
    host, but std::thread is not using it, avoid calling
@@ -102,8 +103,19 @@ thread_pool::set_thread_count (size_t num_threads)
       block_signals blocker;
       for (size_t i = m_thread_count; i < num_threads; ++i)
        {
-         std::thread thread (&thread_pool::thread_function, this);
-         thread.detach ();
+         try
+           {
+             std::thread thread (&thread_pool::thread_function, this);
+             thread.detach ();
+           }
+         catch (const std::system_error &)
+           {
+             /* libstdc++ may not implement std::thread, and will
+                throw an exception on use.  It seems fine to ignore
+                this, and any other sort of startup failure here.  */
+             num_threads = i;
+             break;
+           }
        }
     }
   /* If the new size is smaller, terminate some existing threads.  */
This page took 0.02853 seconds and 4 git commands to generate.