]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.15] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh...
authorSam Gross <colesbury@gmail.com>
Mon, 11 May 2026 18:23:39 +0000 (18:23 +0000)
committerGitHub <noreply@github.com>
Mon, 11 May 2026 18:23:39 +0000 (14:23 -0400)
commit8297d50a63906757a92f86fc7f1eb5064c816b93
tree00b35d6faab0b8e4d3e854780f7a4684f5370cec
parentb4f2e882032d71b2c60d74befdc2615d5596f2fe
[3.15] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) (#149690)

In free-threaded builds, concurrent calls to PyDict_AddWatcher, PyDict_ClearWatcher, PyDict_Watch, and PyDict_Unwatch can race on the shared callback array and the per-dict watcher tags. This change adds a mutex to serialize watcher registration and removal, atomic operations for tag updates, and atomic acquire/release synchronization for callback dispatch in _PyDict_SendEvent.

(cherry picked from commit 8a4895985f42282504d83b9bd0c77b129f95a5d5)

Co-authored-by: Alper <alperyoney@fb.com>
Include/internal/pycore_dict_state.h
Include/internal/pycore_pyatomic_ft_wrappers.h
Lib/test/test_free_threading/test_dict_watcher.py [new file with mode: 0644]
Misc/NEWS.d/next/C_API/2026-02-25-13-37-10.gh-issue-145235.-1ySNR.rst [new file with mode: 0644]
Modules/_testcapi/watchers.c
Objects/dictobject.c
Python/optimizer_analysis.c
Python/pystate.c
Tools/c-analyzer/cpython/ignored.tsv