bpo-30768: Recompute timeout on interrupted lock (GH-4103)

Fix the pthread+semaphore implementation of
PyThread_acquire_lock_timed() when called with timeout > 0 and
intr_flag=0: recompute the timeout if sem_timedwait() is interrupted
by a signal (EINTR).

See also the PEP 475.

The pthread implementation of PyThread_acquire_lock() now fails with
a fatal error if the timeout is larger than PY_TIMEOUT_MAX, as done
in the Windows implementation.

The check prevents any risk of overflow in PyThread_acquire_lock().

Add also PY_DWORD_MAX constant.
This commit is contained in:
Victor Stinner 2017-10-24 16:53:32 -07:00 committed by GitHub
parent 3557b05c5a
commit 850a18e03e
9 changed files with 86 additions and 31 deletions

View file

@ -1363,9 +1363,11 @@ PyInit__thread(void)
if (m == NULL)
return NULL;
timeout_max = PY_TIMEOUT_MAX / 1000000;
time_max = floor(_PyTime_AsSecondsDouble(_PyTime_MAX));
timeout_max = (double)PY_TIMEOUT_MAX * 1e-6;
time_max = _PyTime_AsSecondsDouble(_PyTime_MAX);
timeout_max = Py_MIN(timeout_max, time_max);
/* Round towards minus infinity */
timeout_max = floor(timeout_max);
v = PyFloat_FromDouble(timeout_max);
if (!v)