gh-112075: Make _PyDict_LoadGlobal thread safe#117529
Merged
DinoV merged 2 commits intopython:mainfrom Apr 4, 2024
Merged
Conversation
dcd7ede to
548a7c2
Compare
|
🤖 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. |
colesbury
approved these changes
Apr 4, 2024
| * 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. |
Contributor
There was a problem hiding this comment.
I think we will want it to return a possibly deferred reference soon, but this is good for now.
| #ifdef Py_GIL_DISABLED | ||
| /* namespace 1: globals */ | ||
| ix = _Py_dict_lookup(globals, key, hash, &value); | ||
| ix = _Py_dict_lookup_threadsafe(globals, key, hash, &value); |
Contributor
There was a problem hiding this comment.
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.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this pull request
Apr 17, 2024
Make _PyDict_LoadGlobal threadsafe
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
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.
Currently
_PyDict_LoadGlobalis using the non-thread safe_Py_dict_lookupand 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_lookupthat the dictionary should be locked, and fixes up ordered dict to use the thread safe version where the assertion trips.dictobjects thread-safe in--disable-gilbuilds #112075