aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/thread-pool.cc
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-11-20 08:22:46 -0700
committerTom Tromey <tromey@adacore.com>2020-11-20 08:22:46 -0700
commit14f62a099a0287c858ac7f4882e88736c11ed1cc (patch)
tree4fd1595ed9c281e91572785ba651dd85430dd0eb /gdbsupport/thread-pool.cc
parent9d37f01307db492370a260e3ef9aee10b363fec2 (diff)
downloadgdb-14f62a099a0287c858ac7f4882e88736c11ed1cc.zip
gdb-14f62a099a0287c858ac7f4882e88736c11ed1cc.tar.gz
gdb-14f62a099a0287c858ac7f4882e88736c11ed1cc.tar.bz2
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 <tromey@adacore.com> * thread-pool.cc (thread_pool::set_thread_count): Ignore system errors.
Diffstat (limited to 'gdbsupport/thread-pool.cc')
-rw-r--r--gdbsupport/thread-pool.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/gdbsupport/thread-pool.cc b/gdbsupport/thread-pool.cc
index be9ca22..06586f7 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 <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. */