Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-112075: Accessing a single element should optimistically avoid locking#115109
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
DinoV commented Feb 6, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
1266799 to 2f46a39Compareef7c6ea to 54095deCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Objects/dictobject.c Outdated
| set_keys(mp, new_keys_object(interp, log2_newsize, unicode)); | ||
| if (mp->ma_keys==NULL){ | ||
| mp->ma_keys=oldkeys; | ||
| set_keys(mp, oldkeys); |
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 don't think the possible temporary assignment to NULL is thread-safe without the GIL. Let's assign the result of new_keys_object() to a temporary variable and check that before assigning it to mp->ma_keys.
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.
When I was looking at this function when you made a comment about it on #114741 I realized that the assignment of it to a new empty table isn't right at all! We really need to allocate the new table, copy everything over, and then we can publish it.
Objects/dictobject.c Outdated
| if (hash==-1) | ||
| returnNULL; | ||
| } | ||
| #ifdefPy_GIL_DISABLED |
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.
Does this differ from PyDict_Contains()? Can we just call that?
Uh oh!
There was an error while loading. Please reload this page.
| PyObject*value; | ||
| Py_ssize_tix; | ||
| #ifdefPy_GIL_DISABLED |
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.
This also looks like contains_known_hash
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.
Or does contains_known_hash look like this? 🤔
54095de to af7ddb9Compare
colesbury left a comment
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
af7ddb9 to d608fb3Compare…id locking (python#115109) Makes accessing a single element thread safe and typically lock free
…id locking (python#115109) Makes accessing a single element thread safe and typically lock free
…id locking (python#115109) Makes accessing a single element thread safe and typically lock free
Makes accessing a single element thread safe.
Adds tracking for whether a dictionary is shared or not, but some of this gets duplicated in #115108.
Does not yet deal with all of the atomic assignments that need to happen to make this 100% right, that'll come in a separate PR.
dictobjects thread-safe in--disable-gilbuilds #112075