Skip to content

[3.15] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233)#149690

Merged
colesbury merged 1 commit into
python:3.15from
colesbury:backport-8a48959-3.15
May 11, 2026
Merged

[3.15] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233)#149690
colesbury merged 1 commit into
python:3.15from
colesbury:backport-8a48959-3.15

Conversation

@colesbury
Copy link
Copy Markdown
Contributor

@colesbury colesbury commented May 11, 2026

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 8a48959)

…readed builds (pythongh-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.
(cherry picked from commit 8a48959)

Co-authored-by: Alper <alperyoney@fb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants