-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-133931: Introduce _PyObject_XSetRefDelayed to replace Py_XSETREF #134377
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
Open
corona10
wants to merge
15
commits into
python:main
Choose a base branch
from
corona10:gh-133931
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−9
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
09baa04
gh-133931: Introduce _PyObject_XSetRefDelayed to replace Py_XSETREF
corona10 1ee0825
fix
corona10 753df7a
Address code review
corona10 a168de0
fix
corona10 e7f6d01
fix issue
corona10 6287322
nit
corona10 12a7016
Add comment
corona10 5f42224
Update Objects/obmalloc.c
corona10 388f0ca
Update Include/internal/pycore_pymem.h
corona10 8220367
Update Include/internal/pycore_pymem.h
corona10 c82e0fb
Address code review
corona10 f99c8f1
Add test
corona10 5dc24a3
fix
corona10 99d2718
fix
corona10 7dc6892
Merge remote-tracking branch 'upstream/main' into gh-133931
corona10 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,51 @@ | ||
import concurrent.futures | ||
import unittest | ||
from threading import Barrier | ||
from unittest import TestCase | ||
import random | ||
import time | ||
|
||
from test.support import threading_helper, Py_GIL_DISABLED | ||
|
||
threading_helper.requires_working_threading(module=True) | ||
|
||
|
||
def random_sleep(): | ||
delay_us = random.randint(50, 100) | ||
time.sleep(delay_us * 1e-6) | ||
|
||
def random_string(): | ||
return ''.join(random.choice('0123456789ABCDEF') for _ in range(10)) | ||
|
||
def set_gen_name(g, b): | ||
b.wait() | ||
random_sleep() | ||
g.__name__ = random_string() | ||
return g.__name__ | ||
|
||
def set_gen_qualname(g, b): | ||
b.wait() | ||
random_sleep() | ||
g.__qualname__ = random_string() | ||
return g.__qualname__ | ||
|
||
|
||
@unittest.skipUnless(Py_GIL_DISABLED, "Enable only in FT build") | ||
class TestFTGenerators(TestCase): | ||
NUM_THREADS = 4 | ||
|
||
def concurrent_write_with_func(self, func): | ||
gen = (x for x in range(42)) | ||
for j in range(1000): | ||
with concurrent.futures.ThreadPoolExecutor(max_workers=self.NUM_THREADS) as executor: | ||
b = Barrier(self.NUM_THREADS) | ||
futures = {executor.submit(func, gen, b): i for i in range(self.NUM_THREADS)} | ||
for fut in concurrent.futures.as_completed(futures): | ||
gen_name = fut.result() | ||
self.assertEqual(len(gen_name), 10) | ||
|
||
def test_concurrent_write(self): | ||
with self.subTest(func=set_gen_name): | ||
self.concurrent_write_with_func(func=set_gen_name) | ||
with self.subTest(func=set_gen_qualname): | ||
self.concurrent_write_with_func(func=set_gen_qualname) |
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
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
Oops, something went wrong.
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.
You still need to change the readers to use atomic read with acquire ordering or seq consistency to synchronize with the write here.