summaryrefslogtreecommitdiffstats
path: root/Python/thread_nt.h
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-10-24 23:53:32 (GMT)
committerGitHub <noreply@github.com>2017-10-24 23:53:32 (GMT)
commit850a18e03e8f8309bc8c39adc6e7d51a4568cd9a (patch)
tree56455b89cb152566734d1fc5de5c70029c3baa70 /Python/thread_nt.h
parent3557b05c5a7dfd7d97ddfd3b79aefd53d25e5132 (diff)
downloadcpython-850a18e03e8f8309bc8c39adc6e7d51a4568cd9a.zip
cpython-850a18e03e8f8309bc8c39adc6e7d51a4568cd9a.tar.gz
cpython-850a18e03e8f8309bc8c39adc6e7d51a4568cd9a.tar.bz2
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.
Diffstat (limited to 'Python/thread_nt.h')
-rw-r--r--Python/thread_nt.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index bae8bcc..46df346 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -283,12 +283,13 @@ PyThread_acquire_lock_timed(PyThread_type_lock aLock,
milliseconds = microseconds / 1000;
if (microseconds % 1000 > 0)
++milliseconds;
- if ((DWORD) milliseconds != milliseconds)
- Py_FatalError("Timeout too large for a DWORD, "
- "please check PY_TIMEOUT_MAX");
+ if (milliseconds > PY_DWORD_MAX) {
+ Py_FatalError("Timeout larger than PY_TIMEOUT_MAX");
+ }
}
- else
+ else {
milliseconds = INFINITE;
+ }
dprintf(("%lu: PyThread_acquire_lock_timed(%p, %lld) called\n",
PyThread_get_thread_ident(), aLock, microseconds));