-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-112075: Make _PyDict_LoadGlobal thread safe #117529
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
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
| * 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.
| #ifdef Py_GIL_DISABLED | ||
| /* 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_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