From 1cd95d8a0b61a5b871e1d88e599d6cd2caf8b502 Mon Sep 17 00:00:00 2001 From: peizhilin Date: Tue, 8 Jan 2019 14:08:39 +0800 Subject: [PATCH] use thread local instance test=develop --- paddle/fluid/platform/debug_support.cc | 6 ++++-- paddle/fluid/platform/debug_support.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/platform/debug_support.cc b/paddle/fluid/platform/debug_support.cc index 77ff721020e..a46db932f6d 100644 --- a/paddle/fluid/platform/debug_support.cc +++ b/paddle/fluid/platform/debug_support.cc @@ -23,8 +23,10 @@ template <> std::string PythonDebugSupport::Format() const { std::ostringstream sout; sout << "\nPython Callstacks: \n"; - for (auto& line : info) { - sout << line; + if (!info.empty()) { + for (auto &line : info) { + sout << line; + } } return sout.str(); } diff --git a/paddle/fluid/platform/debug_support.h b/paddle/fluid/platform/debug_support.h index 9d1d54cef76..2c8ee6ed1f9 100644 --- a/paddle/fluid/platform/debug_support.h +++ b/paddle/fluid/platform/debug_support.h @@ -30,8 +30,8 @@ class DebugSupport { public: // Returns the singleton of DebugSupport. static DebugSupport* GetInstance() { - static std::unique_ptr debugSupport_(nullptr); - static std::once_flag init_flag_; + static thread_local std::unique_ptr debugSupport_(nullptr); + static thread_local std::once_flag init_flag_; std::call_once(init_flag_, [&]() { debugSupport_.reset(new DebugSupport()); }); -- GitLab