[3.14] gh-132641: fix race in lru_cache under free-threading (GH-133787) (#133979)

gh-132641: fix race in `lru_cache` under free-threading (GH-133787)

Fix race in `lru_cache` by acquiring critical section on the cache object itself and call the lock held variant of dict functions to modify the underlying dict.
(cherry picked from commit 9ad0c7b0f1)

Co-authored-by: Peter Hawkins <phawkins@google.com>
This commit is contained in:
Miss Islington (bot) 2025-05-14 09:11:38 +02:00 committed by GitHub
parent b94a63c0f1
commit 66d6860439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 94 additions and 5 deletions

View file

@ -2915,6 +2915,11 @@ clear_lock_held(PyObject *op)
ASSERT_CONSISTENT(mp);
}
void
_PyDict_Clear_LockHeld(PyObject *op) {
clear_lock_held(op);
}
void
PyDict_Clear(PyObject *op)
{