diff --git a/cpp/src/db/DB.cpp b/cpp/src/db/DB.cpp index b30f481464..808c87ad1d 100644 --- a/cpp/src/db/DB.cpp +++ b/cpp/src/db/DB.cpp @@ -19,7 +19,6 @@ DB::~DB() {} void DB::Open(const Options& options, DB** dbptr) { *dbptr = nullptr; - /* *dbptr = new DBImpl>(options); */ *dbptr = DBFactory::Build(options); return; } diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 80f433e98b..79266ddca0 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -176,8 +176,7 @@ Status DBImpl::search(const std::string& group_id, size_t k, size_t nq, template void DBImpl::start_timer_task(int interval_) { - std::thread bg_task(&DBImpl::background_timer_task, this, interval_); - bg_task.detach(); + bg_timer_thread_ = std::thread(&DBImpl::background_timer_task, this, interval_); } template @@ -403,6 +402,7 @@ DBImpl::~DBImpl() { bg_build_index_finish_signal_.wait(lock); } } + bg_timer_thread_.join(); std::vector ids; _pMemMgr->serialize(ids); _env->Stop(); diff --git a/cpp/src/db/DBImpl.h b/cpp/src/db/DBImpl.h index 8896a1d48b..d2aed0af1d 100644 --- a/cpp/src/db/DBImpl.h +++ b/cpp/src/db/DBImpl.h @@ -87,6 +87,8 @@ private: bool bg_build_index_started_; std::condition_variable bg_build_index_finish_signal_; + std::thread bg_timer_thread_; + MetaPtr _pMeta; MemManagerPtr _pMemMgr;