Skip to content

Commit

Permalink
_threadmodule: make _thread.lock thread-safe
Browse files Browse the repository at this point in the history
Previously, _thread.lock would modify a shared boolean "locked" after
the underlying lock was released. This swaps the order of those
statements.
  • Loading branch information
colesbury committed Apr 23, 2023
1 parent 5d006db commit d1b5ed1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d1b5ed1

Please sign in to comment.