GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-115999: Add free-threaded specialization for `SEND`. by nascheme · Pull Request #127426 · python/cpython

Conversation

@nascheme

@nascheme nascheme commented Nov 29, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

No additional thread safety changes are required. Note that sending to a generator that is shared between threads is not safe in the free-threaded build.

  • Issue: Make the specializing interpreter thread-safe in --disable-gil builds #115999

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nascheme
pythongh-115999 Add free-threaded specialization for SEND.
77163cb
No additional thread safety changes are required.  Note that sending to
a generator that is shared between threads is not safe in the
free-threaded build.
@nascheme nascheme added skip news topic-free-threading labels Nov 29, 2024
@nascheme
nascheme requested a review from mpage November 29, 2024 20:17
@nascheme
nascheme requested a review from markshannon as a code owner November 29, 2024 20:17
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 29, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Nov 29, 2024
Make the specializing interpreter thread-safe in --disable-gil builds #115999
Closed
@ZeroIntensity

ZeroIntensity commented Nov 29, 2024

Copy link
Copy Markdown
Member

Related: GH-126371 makes native generators thread safe for free-threading. Once this gets merged, I can finish that one up and add any needed locking for the specialization instruction.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nascheme

nascheme commented Nov 30, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I didn't test too much but applying GH-126371 on top of this PR makes the TestRaces.test_racing_send_gen test run without generating TSAN warnings. Without it, there are warnings and CPython sometimes segfaults. So, perhaps no additional changes will be needed to the specialized opcodes to make it safe.

ZeroIntensity reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity ZeroIntensity mentioned this pull request Nov 30, 2024
gh-126366: Make native generators thread safe #126371
Closed
corona10
corona10 reviewed Dec 2, 2024
View reviewed changes

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

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 try to organize unitest codes for specialized opcodes with more understandable function name :)

See:

cpython/Lib/test/test_opcache.py

Lines 1400 to 1418 in c112de1

def binary_subscr_dict():
for _ in range(100):
a = {1: 2, 2: 3}
self.assertEqual(a[1], 2)
self.assertEqual(a[2], 3)
binary_subscr_dict()
self.assert_specialized(binary_subscr_dict, "BINARY_SUBSCR_DICT")
self.assert_no_opcode(binary_subscr_dict, "BINARY_SUBSCR")
def binary_subscr_str_int():
for _ in range(100):
a = "foobar"
for idx, expected in enumerate(a):
self.assertEqual(a[idx], expected)
binary_subscr_str_int()
self.assert_specialized(binary_subscr_str_int, "BINARY_SUBSCR_STR_INT")
self.assert_no_opcode(binary_subscr_str_int, "BINARY_SUBSCR")

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_opcache.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@nascheme
Use more descriptive function names in tests.
e517ccb
mpage
mpage approved these changes Dec 2, 2024
View reviewed changes

@mpage mpage left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM. I left a small suggestion inline to make the implementation of _Py_Specialize_Send a little more concise, but feel free to ignore it if you prefer the current code structure.

I've kicked off benchmark runs for both the default and free-threaded builds for this change. I'll post the results once they're available, likely tomorrow morning.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/specialize.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/specialize.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 2, 2024
@mpage

mpage commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

Performance looks neutral on both the default and free-threaded builds. I think it's still worth merging this to stay consistent with the default build.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nascheme
Small code simplification.
40dac97
@nascheme
nascheme merged commit 276cd66 into python:main Dec 3, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 3, 2024
@nascheme
nascheme deleted the gh-115999-specialize-send branch December 3, 2024 18:25
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@nascheme @srinivasreddy
pythongh-115999: Add free-threaded specialization for SEND (pythong…
f6ebd23
…h-127426)

No additional thread safety changes are required.  Note that sending to
a generator that is shared between threads is currently not safe in the
free-threaded build.
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
@nascheme @ebonnal
pythongh-115999: Add free-threaded specialization for SEND (pythong…
07995d1
…h-127426)

No additional thread safety changes are required.  Note that sending to
a generator that is shared between threads is currently not safe in the
free-threaded build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@corona10 corona10 corona10 left review comments
@mpage mpage mpage approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@nascheme @ZeroIntensity @mpage @corona10
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.