Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145235: Make dict watcher API thread-safe for free-threaded builds#145233

Open
yoney wants to merge 3 commits intopython:mainfrom
yoney:watcher
Open

gh-145235: Make dict watcher API thread-safe for free-threaded builds#145233
yoney wants to merge 3 commits intopython:mainfrom
yoney:watcher

Conversation

@yoney
Copy link
Contributor

@yoneyyoney commentedFeb 25, 2026
edited
Loading

In free-threaded builds, concurrent calls toPyDict_AddWatcher,PyDict_ClearWatcher,PyDict_Watch, andPyDict_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.

Note: Before this change, runningtest.test_free_threading.test_dict_watcher emitted tsan warnings in the free-threaded tsan build.

cc:@colesbury@mpage@DinoV

@yoneyyoney changed the titleMake dict watcher API thread-safe for free-threaded buildsgh-145235: Make dict watcher API thread-safe for free-threaded buildsFeb 25, 2026
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->dict_state.watchers[GLOBALS_WATCHER_ID] == NULL) {
interp->dict_state.watchers[GLOBALS_WATCHER_ID] = globals_watcher_callback;
if (FT_ATOMIC_LOAD_PTR_RELAXED(interp->dict_state.watchers[GLOBALS_WATCHER_ID]) == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A_PyOnceFlag (maybe in JitOptContext) might be a better fit here.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

After looking into it (with Claude),JitOptContext seems to be per-optimization-run so_PyOnceFlag might not the right place. I put it in_Py_dict_state as I couldn't find a better place. It fits in the struct packing without extra space.

@yoney
Copy link
ContributorAuthor

@colesbury Thank you for the review. I’ve addressed the comments.

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

Reviewers

@colesburycolesburycolesbury left review comments

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@ZeroIntensityZeroIntensityAwaiting requested review from ZeroIntensityZeroIntensity is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

@tomasr8tomasr8Awaiting requested review from tomasr8tomasr8 is a code owner

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-SpinnerFidget-Spinner is a code owner

@savannahostrowskisavannahostrowskiAwaiting requested review from savannahostrowskisavannahostrowski is a code owner

@methanemethaneAwaiting requested review from methanemethane is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@yoney@colesbury

[8]ページ先頭

©2009-2026 Movatter.jp