GeezerVison is showing github.com — parking_lot.c should use _PyTime_GetMonotonicClock() when available · Issue #112606 · python/cpython
parking_lot.c should use _PyTime_GetMonotonicClock() when available #112606DescriptionBug report
The _PySemaphore_PlatformWait function in parking_lot.c has three implementations:
WaitForSingleObjectEx (for Windows)
sem_timedwait (Linux and most other POSIX platforms)
pthread_cond_timedwait (macOS and possibly other platforms that don't have sem_timedwait)
We should follow the pattern used in thread_pthread.h where we prefer functions that support CLOCK_MONOTONIC. These are sem_clockwait and pthread_cond_timedwait after setting pthread_condattr_setclock.
Additionally, we should use _PyTime_AsTimespec_clamp instead of _PyTime_AsTimespec (we don't want to raise errors in these code paths).
Note that:
- Windows doesn't need any changes because
WaitForSingleObjectEx isn't relative to any specific clock -- it just takes a timeout for N milliseconds in the future
- macOS doesn't support
pthread_condattr_setclock, so we're stuck with the system clock on macOS. It's not clear to me if we use the pthread_cond_timedwait for any other OS.
Linked PRs
Activitymattprodani commented on Dec 4, 2023 Splitting into two PRs for sem_timedwait and pthread_cond_timedwait implementations. Working on finishing up the condvar implementation to share fields that initialize the proper pthread_condattr_t from thread_pthread.h as per notes.
added a commit that references this issue on Dec 6, 2023gh-112606: Use sem_clockwait with monotonic time when supported in pa… vstinner commented on Dec 6, 2023 As someone writes a fix for the mutex, ping me, I can review it ;-) added a commit that references this issue on Jan 30, 2024gh-112606: Use pthread_cond_timedwait_relative_np() in parking_lot.c … colesbury commented on Oct 8, 2024 ContributorAuthor More actions Closing this as the relevant PRs landed a while ago.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|