From dbbad059f7384fdbe88c570014b96f27ab284468 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 9 Feb 2026 13:39:23 -0600 Subject: [PATCH] fix(sleeper-thread): stop and join before worker reassignment Reassigning SleeperThread could replace a joinable std::thread and trigger std::terminate. I now stop and join any existing worker before reassignment, then reset control state before starting the replacement worker. Signed-off-by: Austin Horstman --- include/util/sleeper_thread.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/util/sleeper_thread.hpp b/include/util/sleeper_thread.hpp index 62d12931..183083cf 100644 --- a/include/util/sleeper_thread.hpp +++ b/include/util/sleeper_thread.hpp @@ -42,6 +42,15 @@ class SleeperThread { } SleeperThread& operator=(std::function func) { + if (thread_.joinable()) { + stop(); + thread_.join(); + } + { + std::lock_guard lck(mutex_); + do_run_ = true; + signal_ = false; + } thread_ = std::thread([this, func] { while (do_run_) { signal_ = false; @@ -92,7 +101,7 @@ class SleeperThread { condvar_.notify_all(); } - auto stop() { + void stop() { { std::lock_guard lck(mutex_); signal_ = true;