From bcd9f5560e01992f23f3e2efc6a7898c0a7fb8c4 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Sat, 24 Oct 2026 16:22:23 +0200 Subject: [PATCH] Document the MSVC timer resolution caveat of Tree::sleep Tree::sleep() waits on a std::condition_variable. On MSVC the wait_for() timeout is rounded up to the system timer resolution (about 15.6 ms, microsoft/STL#2173), so a 1 ms sleep can take ~16 ms and tickWhileRunning() cannot run much faster than 64 Hz on Windows. Add a note to the Tree::sleep() documentation, with the workaround from the STL issue thread (timeBeginPeriod(1)) that needs no library change. Fixes #1134 Co-Authored-By: Claude Opus 5.5 --- include/behaviortree_cpp/bt_factory.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/behaviortree_cpp/bt_factory.h b/include/behaviortree_cpp/bt_factory.h index 9919b4307..82d41c220 100644 --- a/include/behaviortree_cpp/bt_factory.h +++ b/include/behaviortree_cpp/bt_factory.h @@ -133,6 +133,11 @@ class Tree * @param timeout duration of the sleep * @return true if the timeout was NOT reached and the signal was received. * + * @note On MSVC, std::condition_variable::wait_for() rounds the timeout up to the + * system timer resolution (about 15.6 ms), see microsoft/STL#2173. A short sleep, e.g. + * in tickWhileRunning(), can take much longer there. Calling timeBeginPeriod(1) once + * at startup (Windows API, links winmm) restores a 1 ms resolution. + * * */ bool sleep(std::chrono::system_clock::duration timeout);