Uh oh!
There was an error while loading. Please reload this page.
gh-112606: Use sem_clockwait with monotonic time when supported in parking_lot.c - #112733
Conversation
Completes one part of moving `parking_lot.c`'s semaphore waiting to prefer functions that support CLOCK_MONOTONIC. Uses sem_clockwait in the semaphore-based implementation.
colesbury
commented
Dec 5, 2023
Also cc @vstinner - |
vstinner
left a comment
There was a problem hiding this comment.
I wrote similar code in Python/thread_pthread.h. Here is my review.
This change only fix one code path. The code path if _Py_USE_SEMAPHORES is not defined still uses the system clock. pthread_condattr_setclock(&ca, CLOCK_MONOTONIC) can be used for that: see Python/thread_pthread.h.
Unrelated to this PR, I have concerns about _PySemaphore_PlatformWait().
(DWORD) (timeout / 1000000) can overflow in the Windows code path. Using _PyTime_As100Nanoseconds() may be a good start.
PEP 475 "Retry system calls failing with EINTR" is not supported: the caller has to handle Py_PARK_INTR. The problem is that it's quite hard to recompute properly a timeout to take in account time elapsed by the call which failed with Py_PARK_INTR. It would be better to retry on EINTR and recompute the timeout. Similar to what Python/thread_pthread.h does in PyThread_acquire_lock_timed(). For the sem_clockwait() code path, it's easy, since we only have to compute an absolute timestamp once.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mattprodani
commented
Dec 6, 2023
@vstinner Thanks for reviewing, I'm finishing up the remaining |
corona10
commented
Dec 6, 2023
I will take look this PR today |
colesbury
commented
Dec 6, 2023
@vstinner Please see the other PR, which is still a draft, for discussion about the pthreads code path: #112616. I don't think
"Retry system calls failing with EINTR" - Interrupts are properly retried. It happens at a higher level in the abstraction, see |
Completes one part of moving
parking_lot.c's semaphore waiting to prefer functions that supportCLOCK_MONOTONICUsessem_clockwaitin the semaphore-based implementation. Split with previous PR to move support forCLOCK_MONOTONICinpthread_condvar_timplementation to a separate PR.