Skip to content

Commit d1b5ed1

Browse files
committed
_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.
1 parent 5d006db commit d1b5ed1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Modules/_threadmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ lock_PyThread_release_lock(lockobject *self, PyObject *Py_UNUSED(ignored))
206206
return NULL;
207207
}
208208

209-
PyThread_release_lock(self->lock_lock);
210209
self->locked = 0;
210+
PyThread_release_lock(self->lock_lock);
211211
Py_RETURN_NONE;
212212
}
213213

@@ -1393,8 +1393,8 @@ release_sentinel(void *wr_raw)
13931393
if (obj != Py_None) {
13941394
lock = (lockobject *) obj;
13951395
if (lock->locked) {
1396-
PyThread_release_lock(lock->lock_lock);
13971396
lock->locked = 0;
1397+
PyThread_release_lock(lock->lock_lock);
13981398
}
13991399
Py_DECREF(obj);
14001400
}

0 commit comments

Comments
 (0)