From 6f7f2c543a5cfa6f58009434b6850ce60796003b Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Tue, 22 Nov 2022 20:07:25 +0800 Subject: [PATCH] fix core dump at exit Signed-off-by: zhoufeng --- mindspore/core/utils/ms_context.cc | 3 +++ mindspore/core/utils/ms_context.h | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mindspore/core/utils/ms_context.cc b/mindspore/core/utils/ms_context.cc index 72deae2f5de..74677447526 100644 --- a/mindspore/core/utils/ms_context.cc +++ b/mindspore/core/utils/ms_context.cc @@ -40,6 +40,8 @@ std::map kPolicyMap = {{"ge", kMsBackendGePrior}, std::atomic thread_1_must_end(false); MsContext::DeviceSeter MsContext::seter_ = nullptr; +MsContext::LoadPluginError MsContext::load_plugin_error_ = nullptr; +std::shared_ptr MsContext::inst_context_ = nullptr; MsContext::MsContext(const std::string &policy, const std::string &target) { #ifndef ENABLE_SECURITY @@ -124,6 +126,7 @@ MsContext::MsContext(const std::string &policy, const std::string &target) { } std::shared_ptr MsContext::GetInstance() { + static std::once_flag inst_context_init_flag_ = {}; std::call_once(inst_context_init_flag_, [&]() { if (inst_context_ == nullptr) { MS_LOG(DEBUG) << "Create new mindspore context"; diff --git a/mindspore/core/utils/ms_context.h b/mindspore/core/utils/ms_context.h index 1b28e4eeeb3..666384ec625 100644 --- a/mindspore/core/utils/ms_context.h +++ b/mindspore/core/utils/ms_context.h @@ -201,9 +201,8 @@ class MS_CORE_API MsContext { private: static DeviceSeter seter_; - inline static std::once_flag inst_context_init_flag_ = {}; - inline static std::shared_ptr inst_context_ = nullptr; - inline static LoadPluginError load_plugin_error_ = nullptr; + static std::shared_ptr inst_context_; + static LoadPluginError load_plugin_error_; bool bool_params_[MsCtxParam::NUM_BOOL_PARAMS]; int int_params_[MsCtxParam::NUM_INT_PARAMS];