Skip to content

PyDict_Watch and PyDict_Unwatch should use atomic operations in the free threading build #148393

Description

@colesbury

Bug report

Currently, there is a data race when PyDict_Watch/PyDict_Unwatch is called on a dict that another thread may concurrently mutate: the read of _ma_watcher_tag in _PyDict_NotifyEvent (on the mutation path) races with the modification by PyDict_Watch/PyDict_Unwatch. Additionally, concurrent PyDict_Watch/PyDict_Unwatch calls on the same dict (e.g. from different watcher IDs) race with each other, since both are non-atomic read-modify-write operations on _ma_watcher_tag.

In the free threading build, we should use atomic operations for the read of _ma_watcher_tag in _PyDict_NotifyEvent and for the updates performed by PyDict_Watch/PyDict_Unwatch.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions