-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-117657: TSAN Fix race in PyMember_Get
and PyMember_Set
, for Py_T_OBJECT_EX
type
#119368
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
066f365
Add test to reproduce data race on PyMember_Get/Set
dpdani cc2858d
fix race for case `Py_T_OBJECT_EX`
dpdani cff8b44
hide segafulting test
dpdani a14f324
test segafults with many iterations
dpdani 1ee3091
retry path for free threading builds
dpdani 7aa0396
comment
dpdani 419929d
self-review
dpdani ce49aea
revert change in default build
dpdani a4147f1
Merge branch 'refs/heads/main' into tsan-pymember
dpdani 8639eae
missing NULL check
dpdani f30cb20
use critical section instead of relying on weakref flag
dpdani 79396ce
Merge branch 'main' into tsan-pymember
dpdani 99b1bce
review
dpdani 8f273f7
move up
dpdani 798c2f0
suggested new formatting syntax
dpdani cb698b3
fix test
dpdani 737eb09
remove commented code
dpdani 15fdffe
good nit
dpdani 8baaa45
Merge branch 'main' into tsan-pymember
dpdani 1cd2bb0
Update Lib/test/test_free_threading/test_slots.py
colesbury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import threading | ||
from test.support import threading_helper | ||
from unittest import TestCase | ||
|
||
|
||
# import _testcapi | ||
|
||
|
||
def run_in_threads(targets): | ||
"""Run `targets` in separate threads""" | ||
threads = [ | ||
threading.Thread(target=target) | ||
for target in targets | ||
] | ||
for thread in threads: | ||
thread.start() | ||
for thread in threads: | ||
thread.join() | ||
|
||
|
||
@threading_helper.requires_working_threading() | ||
class TestSlots(TestCase): | ||
|
||
def test_object(self): | ||
class Spam: | ||
__slots__ = [ | ||
"eggs", # the Py_T_OBJECT_EX type is missing in | ||
# Modules/_testcapi/structmember.c | ||
] | ||
|
||
def __init__(self, initial_value): | ||
self.eggs = initial_value | ||
|
||
spam = Spam(0) | ||
iters = 1_000_000 | ||
colesbury marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def writer(): | ||
for _ in range(iters): | ||
spam.eggs += 1 | ||
|
||
def reader(): | ||
for _ in range(iters): | ||
eggs = spam.eggs | ||
assert type(eggs) is int | ||
assert 0 <= eggs <= iters | ||
|
||
run_in_threads([writer, reader, reader, reader]) | ||
|
||
# def test_bool(self): | ||
# spam_old = _testcapi._test_structmembersType_OldAPI() | ||
# spam_new = _testcapi._test_structmembersType_NewAPI() | ||
# | ||
# def writer(): | ||
# for _ in range(1_000): | ||
# spam_old.T_BOOL = True | ||
# spam_old.T_BOOL = False # separate code path for True/False | ||
# spam_new.T_BOOL = True | ||
# spam_new.T_BOOL = False | ||
# | ||
# def reader(): | ||
# for _ in range(1_000): | ||
# spam_old.T_BOOL | ||
# spam_new.T_BOOL | ||
# | ||
# run_in_threads([writer, reader, reader, reader]) |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not using this now, should I leave it in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove it then.