]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh...
authorSam Gross <colesbury@gmail.com>
Tue, 12 May 2026 17:21:31 +0000 (17:21 +0000)
committerGitHub <noreply@github.com>
Tue, 12 May 2026 17:21:31 +0000 (13:21 -0400)
commitd6b6fd70c4afce0210372945bca8e0bc7aa8cabf
tree518735806663dbad30c350c57dadae1aaf8034bf
parentf3c0e0e47a25c79be185465ea21ab969738f4088
[3.14] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) (#149691)

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>
Doc/data/python3.14.abi
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