From 71a000c7d1768f4be720a0249a580c28864c50b9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 17 Nov 2023 23:42:08 +0100 Subject: [PATCH] gh-108724: Use _PyTime_GetMonotonicClock() in parking_lot.c Using a system clock causes issues when it's being updated by the system administrator, NTP, Daylight Saving Time, or anything else. Sadly, on Windows, the monotonic clock resolution is around 15.6 ms. Example: https://github.com/python/cpython/issues/85876 --- Python/parking_lot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/parking_lot.c b/Python/parking_lot.c index 664e622cc17474..6afb4b63431f3b 100644 --- a/Python/parking_lot.c +++ b/Python/parking_lot.c @@ -118,7 +118,7 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout) if (timeout >= 0) { struct timespec ts; - _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout); + _PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout); _PyTime_AsTimespec(deadline, &ts); err = sem_timedwait(&sema->platform_sem, &ts); @@ -150,7 +150,7 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout) if (timeout >= 0) { struct timespec ts; - _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout); + _PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout); _PyTime_AsTimespec(deadline, &ts); err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);