fix core dump at exit

Signed-off-by: zhoufeng <zhoufeng54@huawei.com>
This commit is contained in:
zhoufeng 2022-11-22 20:07:25 +08:00
parent c29114b12e
commit 6f7f2c543a
2 changed files with 5 additions and 3 deletions

View File

@ -40,6 +40,8 @@ std::map<std::string, MsBackendPolicy> kPolicyMap = {{"ge", kMsBackendGePrior},
std::atomic<bool> thread_1_must_end(false);
MsContext::DeviceSeter MsContext::seter_ = nullptr;
MsContext::LoadPluginError MsContext::load_plugin_error_ = nullptr;
std::shared_ptr<MsContext> 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> 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";

View File

@ -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<MsContext> inst_context_ = nullptr;
inline static LoadPluginError load_plugin_error_ = nullptr;
static std::shared_ptr<MsContext> inst_context_;
static LoadPluginError load_plugin_error_;
bool bool_params_[MsCtxParam::NUM_BOOL_PARAMS];
int int_params_[MsCtxParam::NUM_INT_PARAMS];