From d1b5ed128e2df9f623969fe59627dc8a19fcf024 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 26 Nov 2019 19:22:59 -0500 Subject: [PATCH] _threadmodule: make _thread.lock thread-safe Previously, _thread.lock would modify a shared boolean "locked" after the underlying lock was released. This swaps the order of those statements. --- Modules/_threadmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index ec467ce64a..97667920c3 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -206,8 +206,8 @@ lock_PyThread_release_lock(lockobject *self, PyObject *Py_UNUSED(ignored)) return NULL; } - PyThread_release_lock(self->lock_lock); self->locked = 0; + PyThread_release_lock(self->lock_lock); Py_RETURN_NONE; } @@ -1393,8 +1393,8 @@ release_sentinel(void *wr_raw) if (obj != Py_None) { lock = (lockobject *) obj; if (lock->locked) { - PyThread_release_lock(lock->lock_lock); lock->locked = 0; + PyThread_release_lock(lock->lock_lock); } Py_DECREF(obj); }