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-136870: fix data races in instrumentation of bytecode#136994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kumaraditya303 merged 3 commits intopython:mainfromkumaraditya303:instrumentation
Jul 24, 2025

Conversation

@kumaraditya303
Copy link
Contributor

@kumaraditya303kumaraditya303 commentedJul 22, 2025
edited
Loading

De-instrumenting code objects modifies the thread local bytecode for all threads as such, holding the critical section on the code object is not sufficient and leads to data races. In this PR, the de-instrumentation is now performed under a stop the world pause as such no thread races with executing the thread local bytecode while it is being de-instrumented.

@colesbury
Copy link
Contributor

I think this makes sense, but it'd be helpful if@DinoV and@mpage can also take a look at it.

From our discussion, locking code objects forde-instrumentation after calling tools isn't sufficient because other threads may be in the middle of running those code objects. We need a stop the world pause there, given the current design.

kumaraditya303 reacted with thumbs up emoji

@mpage
Copy link
Contributor

I think this makes sense, but to make sure I understand correctly, the issue here is that without this change other threads may be using the tools concurrently with their removal. Is that right?

@kumaraditya303
Copy link
ContributorAuthor

the issue here is that without this change other threads may be using the tools concurrently with their removal. Is that right?

The issue is that while the tools are removed which involves modifying thread local bytecode inMODIFY_BYTECODE for all threads, other threads can be concurrently running the bytecode which causes data race.

@mpage
Copy link
Contributor

The issue is that while the tools are removed which involves modifying thread local bytecode in MODIFY_BYTECODE for all threads, other threads can be concurrently running the bytecode which causes data race.

Ah, ok. We intended to use atomics to avoid data races on the bytecode; looks we missed some places that should use them. Stop-the-world certainly fixes them and is easier to reason about, but it does come with a performance cost. I think that tradeoff is probably acceptable for now and we can revisit later if need be.

@colesbury
Copy link
Contributor

I think we should include a NEWS entry and request a backport to 3.14

kumaraditya303 reacted with thumbs up emoji

@kumaraditya303kumaraditya303 added topic-free-threading interpreter-core(Objects, Python, Grammar, and Parser dirs) needs backport to 3.14bugs and security fixes labelsJul 24, 2025
@kumaraditya303kumaraditya303enabled auto-merge (squash)July 24, 2025 17:41
@kumaraditya303kumaraditya303 merged commit9a6b60a intopython:mainJul 24, 2025
47 checks passed
@miss-islington-app
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJul 24, 2025
…nGH-136994)De-instrumenting code objects modifies the thread local bytecode for all threads as such, holding the critical section on the code object is not sufficient and leads to data races. Now, the de-instrumentation is now performed under a stop the world pause as such no thread races with executing the thread local bytecode while it is being de-instrumented.(cherry picked from commit9a6b60a)Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app
Copy link

GH-137082 is a backport of this pull request to the3.14 branch.

hugovk pushed a commit that referenced this pull requestJul 28, 2025
…36994) (#137082)Co-authored-by: Kumar Aditya <kumaraditya@python.org>Co-authored-by: Zachary Ware <zach@python.org>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull requestAug 4, 2025
…n#136994)De-instrumenting code objects modifies the thread local bytecode for all threads as such, holding the critical section on the code object is not sufficient and leads to data races. Now, the de-instrumentation is now performed under a stop the world pause as such no thread races with executing the thread local bytecode while it is being de-instrumented.
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull requestAug 19, 2025
…n#136994)De-instrumenting code objects modifies the thread local bytecode for all threads as such, holding the critical section on the code object is not sufficient and leads to data races. Now, the de-instrumentation is now performed under a stop the world pause as such no thread races with executing the thread local bytecode while it is being de-instrumented.
kumaraditya303 added a commit to miss-islington/cpython that referenced this pull requestSep 9, 2025
…pythonGH-136994) (python#137082)Co-authored-by: Kumar Aditya <kumaraditya@python.org>Co-authored-by: Zachary Ware <zach@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@colesburycolesburycolesbury approved these changes

@DinoVDinoVAwaiting requested review from DinoV

@mpagempageAwaiting requested review from mpage

Assignees

No one assigned

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@kumaraditya303@colesbury@mpage

[8]ページ先頭

©2009-2025 Movatter.jp