Skip to content

gh-113956: Make intern_common thread-safe in free-threaded build#148886

Merged
colesbury merged 2 commits intopython:mainfrom
colesbury:gh-113956-intern-common-thread-safe
Apr 23, 2026
Merged

gh-113956: Make intern_common thread-safe in free-threaded build#148886
colesbury merged 2 commits intopython:mainfrom
colesbury:gh-113956-intern-common-thread-safe

Conversation

@colesbury
Copy link
Copy Markdown
Contributor

@colesbury colesbury commented Apr 22, 2026

Avoid racing with the owning thread's refcount operations when immortalizing an interned string: if we don't own it and its refcount isn't merged, intern a copy we own instead. Use atomic stores in _Py_SetImmortalUntracked so concurrent atomic reads are race-free.

Avoid racing with the owning thread's refcount operations when
immortalizing an interned string: if we don't own it and its refcount
isn't merged, intern a copy we own instead. Use atomic stores in
_Py_SetImmortalUntracked so concurrent atomic reads are race-free.
@colesbury colesbury marked this pull request as ready for review April 22, 2026 19:49
@colesbury colesbury requested a review from mpage April 22, 2026 19:50
@colesbury colesbury merged commit 4629c22 into python:main Apr 23, 2026
60 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@colesbury colesbury deleted the gh-113956-intern-common-thread-safe branch April 23, 2026 18:43
@miss-islington-app
Copy link
Copy Markdown

Sorry, @colesbury, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 4629c2215a9a4b3d1ec4a306cd4dd7d11dcfebb4 3.14

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 23, 2026

GH-148927 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Apr 23, 2026
colesbury added a commit that referenced this pull request Apr 23, 2026
…ld (gh-148886) (#148927)

Avoid racing with the owning thread's refcount operations when
immortalizing an interned string: if we don't own it and its refcount
isn't merged, intern a copy we own instead. Use atomic stores in
_Py_SetImmortalUntracked so concurrent atomic reads are race-free.

(cherry picked from commit 4629c22)
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