gh-129533: Update PyGC_Enable/Disable/IsEnabled to use atomic operation #129563
Merged
corona10 merged 7 commits intopython:mainfrom Feb 6, 2025
Merged
gh-129533: Update PyGC_Enable/Disable/IsEnabled to use atomic operation #129563corona10 merged 7 commits intopython:mainfrom
corona10 merged 7 commits intopython:mainfrom
Conversation
Member
Author
|
TSAN is passed at my local machine: |
corona10
commented
Feb 2, 2025
Python/gc_free_threading.c
Outdated
| int old_state = gcstate->enabled; | ||
| gcstate->enabled = 0; | ||
| int old_state = _Py_atomic_load_int(&(gcstate->enabled)); | ||
| while (!_Py_atomic_compare_exchange_int(&gcstate->enabled, &old_state, 0)); |
Member
Author
There was a problem hiding this comment.
We don't need to update old_state explicitly since __atomic_compare_exchange_n automatically handle.
https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gcc/_005f_005fatomic-Builtins.html
Member
Author
|
cc @hawkinsp |
mpage
reviewed
Feb 2, 2025
Co-authored-by: mpage <mpage@cs.stanford.edu>
vstinner
approved these changes
Feb 2, 2025
Python/gc_free_threading.c
Outdated
| GCState *gcstate = get_gc_state(); | ||
| int old_state = gcstate->enabled; | ||
| gcstate->enabled = 1; | ||
| int old_state = _Py_atomic_exchange_int(&gcstate->enabled, 1); |
Member
There was a problem hiding this comment.
You can remove the old_state variable. Same remark in PyGC_Disable() and PyGC_IsEnabled().
kumaraditya303
approved these changes
Feb 2, 2025
Member
Author
|
Waiting @pablogsal before merging this PR :) |
|
Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Sorry, @corona10, I could not cleanly backport this to |
corona10
added a commit
to corona10/cpython
that referenced
this pull request
Feb 6, 2025
…operation (pythongh-129563) (cherry picked from commit b184abf)
|
GH-129756 is a backport of this pull request to the 3.13 branch. |
corona10
added a commit
that referenced
this pull request
Feb 6, 2025
srinivasreddy
pushed a commit
to srinivasreddy/cpython
that referenced
this pull request
Feb 7, 2025
cmaloney
pushed a commit
to cmaloney/cpython
that referenced
this pull request
Feb 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.