https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7c8e7f92e3ce85de1fe966ad9bba8307df796e94
commit 7c8e7f92e3ce85de1fe966ad9bba8307df796e94 Author: Corinna Vinschen <cori...@vinschen.de> AuthorDate: Wed Jul 16 11:26:15 2025 +0200 Commit: Corinna Vinschen <cori...@vinschen.de> CommitDate: Wed Jul 16 12:16:57 2025 +0200 Cygwin: clocks: use InterlockedCompareExchange64 The clock init functions checked timer ticks/period for 0 and then called InterlockedExchange64 if the value was still 0. This is not quite as atomic as it was supposed to be. Use InterlockedCompareExchange64 instead. Fixes: 2b72887ac834b ("Cygwin: clocks: fix a hang on pre-Windows 10 machines") Signed-off-by: Corinna Vinschen <cori...@vinschen.de> (cherry picked from commit 167ace9a6d9605f67cd52369dd1e7758ec0d0af5) Diff: --- winsup/cygwin/clock.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/clock.cc b/winsup/cygwin/clock.cc index 2a4e86922b4a..dc940906edb0 100644 --- a/winsup/cygwin/clock.cc +++ b/winsup/cygwin/clock.cc @@ -32,22 +32,19 @@ system_tickcount_period () void inline clk_t::init () { - if (!period) - InterlockedExchange64 (&period, system_tickcount_period ()); + InterlockedCompareExchange64 (&period, system_tickcount_period (), 0); } void inline clk_realtime_t::init () { - if (!ticks_per_sec) - InterlockedExchange64 (&ticks_per_sec, system_qpc_tickspersec ()); + InterlockedCompareExchange64 (&ticks_per_sec, system_qpc_tickspersec (), 0); } void inline clk_monotonic_t::init () { - if (!ticks_per_sec) - InterlockedExchange64 (&ticks_per_sec, system_qpc_tickspersec ()); + InterlockedCompareExchange64 (&ticks_per_sec, system_qpc_tickspersec (), 0); } int