https://github.com/python/cpython/commit/85404a02ba9e52776c4a16a1b2dc473c47972dac commit: 85404a02ba9e52776c4a16a1b2dc473c47972dac branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: kumaraditya303 <[email protected]> date: 2026-06-11T16:34:26Z summary:
[3.15] gh-151228: fix data race on clearing embedded dict values (GH-151330) (#151359) gh-151228: fix data race on clearing embedded dict values (GH-151330) (cherry picked from commit 6112d70abee2455bfa44a76a49a5a80472e21134) Co-authored-by: Kumar Aditya <[email protected]> files: M Lib/test/test_free_threading/test_dict.py M Objects/dictobject.c diff --git a/Lib/test/test_free_threading/test_dict.py b/Lib/test/test_free_threading/test_dict.py index dfe0634211d4b02..ad23290a92ab345 100644 --- a/Lib/test/test_free_threading/test_dict.py +++ b/Lib/test/test_free_threading/test_dict.py @@ -296,6 +296,24 @@ def reader(): threading_helper.run_concurrently([clearer, reader, reader]) + def test_racing_embedded_values_clear_and_lookup(self): + class C: + pass + + obj = C() + def writer(): + for _ in range(1000): + obj.x = 1 + obj.y = 2 + obj.z = 3 + obj.__dict__.clear() + + def reader(): + for _ in range(1000): + obj.__dict__.get('x') + + threading_helper.run_concurrently([writer, reader, reader]) + def test_racing_dict_update_and_method_lookup(self): # gh-144295: test race between dict modifications and method lookups. # Uses BytesIO because the race requires a type without Py_TPFLAGS_INLINE_VALUES diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e279c8765dd464a..25dc81f726f59cb 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -3039,7 +3039,7 @@ clear_embedded_values(PyDictValues *values, Py_ssize_t nentries) assert(nentries <= SHARED_KEYS_MAX_SIZE); for (Py_ssize_t i = 0; i < nentries; i++) { refs[i] = values->values[i]; - values->values[i] = NULL; + FT_ATOMIC_STORE_PTR_RELEASE(values->values[i], NULL); } values->size = 0; for (Py_ssize_t i = 0; i < nentries; i++) { _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
