-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
gh-112075: Make _PyDict_LoadGlobal thread safe #117529
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. |
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
@@ -2343,11 +2343,12 @@ _PyDict_GetItemStringWithError(PyObject *v, const char *key) | |||
* Raise an exception and return NULL if an error occurred (ex: computing the | |||
* 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. |
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 think we will want it to return a possibly deferred reference soon, but this is good for now.
/* namespace 1: globals */ | ||
ix = _Py_dict_lookup(globals, key, hash, &value); | ||
ix = _Py_dict_lookup_threadsafe(globals, key, hash, &value); |
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 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.
Make _PyDict_LoadGlobal threadsafe
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.dict
objects thread-safe in--disable-gil
builds #112075