diff --git a/src/ripple/core/impl/ThreadEntry.cpp b/src/ripple/core/impl/ThreadEntry.cpp index 1649094de..97efdae9c 100644 --- a/src/ripple/core/impl/ThreadEntry.cpp +++ b/src/ripple/core/impl/ThreadEntry.cpp @@ -22,19 +22,25 @@ #include #include +#include #include #include namespace ripple { #ifndef NO_LOG_UNHANDLED_EXCEPTIONS -namespace detail { -thread_local -std::string threadName; +static boost::thread_specific_ptr threadName; +namespace detail { void setThreadName(std::string name) { - threadName = std::move(name); + try + { + threadName.reset(new std::string{std::move(name)}); + } + catch(...) + { + } } } @@ -42,27 +48,28 @@ void terminateHandler() { if (std::current_exception()) { + std::string const name = threadName.get() ? *threadName.get() : "Unknown"; try { throw; } catch (const std::exception& e) { - std::cerr << detail::threadName << ": " << e.what () << '\n'; + std::cerr << name << ": " << e.what () << '\n'; JLOG(debugLog().fatal()) - << detail::threadName << ": " << e.what () << '\n'; + << name << ": " << e.what () << '\n'; } catch (boost::coroutines::detail::forced_unwind const&) { - std::cerr << detail::threadName << ": forced_unwind\n"; + std::cerr << name << ": forced_unwind\n"; JLOG(debugLog().fatal()) - << detail::threadName << ": forced_unwind\n"; + << name << ": forced_unwind\n"; } catch (...) { - std::cerr << detail::threadName << ": unknown exception\n"; + std::cerr << name << ": unknown exception\n"; JLOG (debugLog ().fatal ()) - << detail::threadName << ": unknown exception\n"; + << name << ": unknown exception\n"; } } }