Bug 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
Bug report
The
_PySemaphore_PlatformWaitfunction 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 havesem_timedwait)We should follow the pattern used in
thread_pthread.hwhere we prefer functions that support CLOCK_MONOTONIC. These aresem_clockwaitandpthread_cond_timedwaitafter settingpthread_condattr_setclock.Additionally, we should use
_PyTime_AsTimespec_clampinstead of_PyTime_AsTimespec(we don't want to raise errors in these code paths).Note that:
WaitForSingleObjectExisn't relative to any specific clock -- it just takes a timeout for N milliseconds in the futurepthread_condattr_setclock, so we're stuck with the system clock on macOS. It's not clear to me if we use thepthread_cond_timedwaitfor any other OS.Linked PRs
pthread_cond_timedwait_relative_npin parking_lot.c when available #112616