]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233)
authorAlper <alperyoney@fb.com>
Mon, 11 May 2026 15:39:55 +0000 (08:39 -0700)
committerGitHub <noreply@github.com>
Mon, 11 May 2026 15:39:55 +0000 (11:39 -0400)
commit8a4895985f42282504d83b9bd0c77b129f95a5d5
tree2e7b289b11edc49db69a2d3d6c165ba87e026bc3
parentfadd9bc14e43041c84bb8d06824990264fe1434a
gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233)

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.
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