From c5ea31316daa81c17c25c851032ce242868b518c Mon Sep 17 00:00:00 2001 From: zhagnlu <1542303831@qq.com> Date: Sat, 14 Oct 2023 12:10:05 +0800 Subject: [PATCH] Fix glog thread-safe bug for standalone mode (#27703) Signed-off-by: luzhang Co-authored-by: luzhang --- internal/core/src/segcore/segcore_init_c.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/core/src/segcore/segcore_init_c.cpp b/internal/core/src/segcore/segcore_init_c.cpp index fefe455c25786..5ebf53f651f01 100644 --- a/internal/core/src/segcore/segcore_init_c.cpp +++ b/internal/core/src/segcore/segcore_init_c.cpp @@ -15,6 +15,9 @@ #include "segcore/segcore_init_c.h" namespace milvus::segcore { + +std::once_flag close_glog_once; + extern "C" void SegcoreInit(const char* conf_file) { milvus::config::KnowhereInitImpl(conf_file); @@ -72,9 +75,11 @@ SegcoreSetSimdType(const char* value) { extern "C" void SegcoreCloseGlog() { - if (google::IsGoogleLoggingInitialized()) { - google::ShutdownGoogleLogging(); - } + std::call_once(close_glog_once, [&]() { + if (google::IsGoogleLoggingInitialized()) { + google::ShutdownGoogleLogging(); + } + }); } extern "C" int32_t