summaryrefslogtreecommitdiffstats
path: root/Python/thread_nt.h
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-03-11 23:57:16 (GMT)
committerGitHub <noreply@github.com>2020-03-11 23:57:16 (GMT)
commit60b1b5ac56fe6099a3d358dc9d6cd6ec72fce2d8 (patch)
tree270f3caa2ecb723691b690c4e5b6813ee8a7e6ef /Python/thread_nt.h
parentcd07b4da659cb5e86fe7c856aca866b9db466fce (diff)
downloadcpython-60b1b5ac56fe6099a3d358dc9d6cd6ec72fce2d8.zip
cpython-60b1b5ac56fe6099a3d358dc9d6cd6ec72fce2d8.tar.gz
cpython-60b1b5ac56fe6099a3d358dc9d6cd6ec72fce2d8.tar.bz2
bpo-39847: EnterNonRecursiveMutex() uses GetTickCount64() (GH-18780)
The 32-bit (49-day) TickCount relied on in EnterNonRecursiveMutex can overflow in the gap between the 'target' time and the 'now' time WaitForSingleObjectEx returns, causing the loop to think it needs to wait another 49 days. This is most likely to happen when the machine is hibernated during WaitForSingleObjectEx. This makes acquiring a lock/event/etc from the _thread or threading module appear to never timeout. Replace with GetTickCount64 - this is OK now Python no longer supports XP which lacks it, and is in use for time.monotonic(). Co-authored-by: And Clover <and.clover@bromium.com> (cherry picked from commit 64838ce7172c7a92183b39b22504b433a33a884d) Co-authored-by: bobince <and+github@doxdesk.com>
Diffstat (limited to 'Python/thread_nt.h')
-rw-r--r--Python/thread_nt.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index a5246dd..23d585c 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -75,16 +75,16 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
}
} else if (milliseconds != 0) {
/* wait at least until the target */
- DWORD now, target = GetTickCount() + milliseconds;
+ ULONGLONG now, target = GetTickCount64() + milliseconds;
while (mutex->locked) {
if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, (long long)milliseconds*1000) < 0) {
result = WAIT_FAILED;
break;
}
- now = GetTickCount();
+ now = GetTickCount64();
if (target <= now)
break;
- milliseconds = target-now;
+ milliseconds = (DWORD)(target-now);
}
}
if (!mutex->locked) {