From: Tom Tromey Date: Fri, 20 Nov 2020 15:22:46 +0000 (-0700) Subject: Ignore system_error in thread startup X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=14f62a099a0287c858ac7f4882e88736c11ed1cc;p=binutils-gdb.git Ignore system_error in thread startup 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 * thread-pool.cc (thread_pool::set_thread_count): Ignore system errors. --- diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 2e5b3fa8004..d1e46a3dca8 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,8 @@ +2020-11-20 Tom Tromey + + * thread-pool.cc (thread_pool::set_thread_count): Ignore system + errors. + 2020-11-10 Tom Tromey PR build/26848: diff --git a/gdbsupport/thread-pool.cc b/gdbsupport/thread-pool.cc index be9ca22682a..06586f7da03 100644 --- a/gdbsupport/thread-pool.cc +++ b/gdbsupport/thread-pool.cc @@ -25,6 +25,7 @@ #include "gdbsupport/alt-stack.h" #include "gdbsupport/block-signals.h" #include +#include /* 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. */