From 335688909b85d958132564032306f29d4321e912 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 29 Mar 2023 18:04:19 +0200 Subject: [PATCH] Document why Timer::TimerThreadProc() can use Timer members during Timer#~Timer() call --- lib/base/timer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 973888e9f..4de5d7e0e 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -296,6 +296,11 @@ void Timer::TimerThreadProc() break; auto it = idx.begin(); + + // timer->~Timer() may be called at any moment (if the last + // smart pointer gets destroyed) or even already waiting for + // l_TimerMutex (before doing anything else) which we have + // locked at the moment. Until our unlock using *timer is safe. Timer *timer = *it; ch::time_point> next (ch::duration(timer->m_Next));