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

gh-112075: Make _PyDict_LoadGlobal thread safe by DinoV · Pull Request #117529 · python/cpython · GitHub

/ cpython Public

gh-112075: Make _PyDict_LoadGlobal thread safe - #117529

Merged
DinoV merged 2 commits into
python:mainfrom
DinoV:nogil_dict_loadglobal
Apr 4, 2024
Merged

gh-112075: Make _PyDict_LoadGlobal thread safe#117529
DinoV merged 2 commits into
python:mainfrom
DinoV:nogil_dict_loadglobal

Conversation

DinoV commented Apr 4, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

Currently _PyDict_LoadGlobal is using the non-thread safe _Py_dict_lookup and isn't locking the dictionaries. This switches to using the thread safe version and modifies the function to return a new reference.

It also adds an assertion for _Py_dict_lookup that the dictionary should be locked, and fixes up ordered dict to use the thread safe version where the assertion trips.

DinoV force-pushed the nogil_dict_loadglobal branch from dcd7ede to 548a7c2 Compare April 4, 2024 00:35
DinoV requested a review from colesbury April 4, 2024 01:03
DinoV marked this pull request as ready for review April 4, 2024 01:03
DinoV changed the title Draft gh-112075: Make _PyDict_LoadGlobal thread safe gh-112075: Make _PyDict_LoadGlobal thread safe Apr 4, 2024
colesbury added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Apr 4, 2024

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 548a7c2 🤖

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Apr 4, 2024

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

LGTM

Comment thread Objects/dictobject.c
* key hash failed, key comparison failed, ...). Return NULL if the key doesn't
* exist. Return the value if the key exists.
*
* Returns a new reference.

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

I think we will want it to return a possibly deferred reference soon, but this is good for now.

Comment thread Objects/dictobject.c
#ifdef Py_GIL_DISABLED
/* namespace 1: globals */
ix = _Py_dict_lookup(globals, key, hash, &value);
ix = _Py_dict_lookup_threadsafe(globals, key, hash, &value);

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

I think this pattern might be simpler if we define _Py_dict_lookup_threadsafe in the default build as _Py_dict_lookup_threadsafe + Py_XNewRef().

We could use it in dict_subscript and dict_get_impl as well.

DinoV merged commit 434bc59 into python:main Apr 4, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
DinoV deleted the nogil_dict_loadglobal branch May 31, 2024 18:22
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