diff --git a/libkineto/src/ConfigLoader.cpp b/libkineto/src/ConfigLoader.cpp index d5ed96508..1f7002c6c 100644 --- a/libkineto/src/ConfigLoader.cpp +++ b/libkineto/src/ConfigLoader.cpp @@ -166,13 +166,17 @@ void ConfigLoader::startThread() { } } +void ConfigLoader::signalStop() { + stopFlag_ = true; + { + std::lock_guard lock(updateThreadMutex_); + updateThreadCondVar_.notify_one(); + } +} + void ConfigLoader::stopThread() { + signalStop(); if (updateThread_) { - stopFlag_ = true; - { - std::lock_guard lock(updateThreadMutex_); - updateThreadCondVar_.notify_one(); - } if (updateThread_->joinable()) { updateThread_->join(); } diff --git a/libkineto/src/ConfigLoader.h b/libkineto/src/ConfigLoader.h index 671b21b8b..efd5f3883 100644 --- a/libkineto/src/ConfigLoader.h +++ b/libkineto/src/ConfigLoader.h @@ -87,8 +87,13 @@ class ConfigLoader { std::string getConfString(); - // Stop the background polling thread. Safe to call multiple times. - // Exposed for embedders that need to join the thread before other + // Signal the background polling thread to stop without joining it. + // Use this when joining is unsafe (e.g., the thread may be blocked on a + // lock held by the caller). The thread will exit on its next loop iteration. + void signalStop(); + + // Stop the background polling thread and join it. Safe to call multiple + // times. Exposed for embedders that need to join the thread before other // singletons are destroyed. void stopThread();