FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-128100: Atomic dict load in _PyObject_GenericGetAttrWithDict by wrongnull · Pull Request #128297 · python/cpython · GitHub

/ cpython Public

gh-128100: Atomic dict load in _PyObject_GenericGetAttrWithDict - #128297

Merged
colesbury merged 4 commits into
python:mainfrom
wrongnull:ft-atomic-dict-load
Dec 30, 2024
Merged

gh-128100: Atomic dict load in _PyObject_GenericGetAttrWithDict#128297
colesbury merged 4 commits into
python:mainfrom
wrongnull:ft-atomic-dict-load

Conversation

wrongnull commented Dec 27, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

This is my very first attempt in free-threading in cpython. So that I would be happy to get some criticism

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for taking a shot at this. I haven't dove too deep into the issue so take my review with a grain of salt.

Comment thread Objects/object.c Outdated
}
else {
Py_BEGIN_CRITICAL_SECTION(obj);
#ifdef DISABLE_GIL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This should be Py_GIL_DISABLED.

Comment thread Objects/object.c Outdated
else {
Py_BEGIN_CRITICAL_SECTION(obj);
#ifdef DISABLE_GIL
PyObject **dictptr = _Py_atomic_load_ptr(_PyObject_ComputedDictPointer(obj));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is the wrong thing to load atomically--dereferencing it should be the atomic operation. In fact, this doesn't do what you think it does: _Py_atomic_load* takes a pointer, and the thing that it points to gets atomically loaded and returned.

Comment thread Objects/object.c Outdated
dict = (PyObject *)_PyObject_GetManagedDict(obj);
}
else {
Py_BEGIN_CRITICAL_SECTION(obj);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In general, we don't need to lock something if we're going to use one of the _Py_atomic APIs, and vice versa.

Comment thread Objects/object.c
PyObject **dictptr = _PyObject_ComputedDictPointer(obj);
#endif
if (dictptr) {
dict = *dictptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Here is where the atomic load should be. (And, as Sam said in the issue, we want _Py_atomic_load_ptr_acquire instead of plain old _Py_atomic_load_ptr.)

colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The change looks good. Let's drop the test for now as it's not catching any TSAN data races even with repeated runs before this change. We can write a better test when we address the second half of the issue.

It wasn't reporting any TSAN failures before the PR.
colesbury enabled auto-merge (squash) December 30, 2024 20:15
colesbury merged commit 47d2cb8 into python:main Dec 30, 2024
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025

Copy link
Copy Markdown
Member

@colesbury Was this supposed to get backported to 3.13?

colesbury added the needs backport to 3.13 bugs and security fixes label Feb 10, 2025

Copy link
Copy Markdown

Thanks @wrongnull for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 10, 2025
…ttrWithDict` (pythonGH-128297)

(cherry picked from commit 47d2cb8)

Co-authored-by: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com>

bedevere-app Bot commented Feb 10, 2025

Copy link
Copy Markdown

GH-129979 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Feb 10, 2025
colesbury pushed a commit that referenced this pull request Feb 10, 2025
…AttrWithDict` (GH-128297) (GH-129979)

(cherry picked from commit 47d2cb8)

Co-authored-by: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL