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

gh-112075: Accessing a single element should optimistically avoid locking by DinoV · Pull Request #115109 · python/cpython · GitHub

/ cpython Public

gh-112075: Accessing a single element should optimistically avoid locking - #115109

Merged
DinoV merged 2 commits into
python:mainfrom
DinoV:nogil_dict_get_threadsafe
Feb 21, 2024
Merged

gh-112075: Accessing a single element should optimistically avoid locking#115109
DinoV merged 2 commits into
python:mainfrom
DinoV:nogil_dict_get_threadsafe

Conversation

DinoV commented Feb 6, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

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.

DinoV force-pushed the nogil_dict_get_threadsafe branch from 1266799 to 2f46a39 Compare February 6, 2024 22:49
DinoV force-pushed the nogil_dict_get_threadsafe branch 8 times, most recently from ef7c6ea to 54095de Compare February 7, 2024 20:31
DinoV requested a review from colesbury February 7, 2024 20:48
DinoV marked this pull request as ready for review February 7, 2024 20:58
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
Comment on lines +1792 to +1794
set_keys(mp, new_keys_object(interp, log2_newsize, unicode));
if (mp->ma_keys == NULL) {
mp->ma_keys = oldkeys;
set_keys(mp, oldkeys);

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 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.

Copy link
Copy Markdown
Contributor Author

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

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.

Comment thread Objects/dictobject.c Outdated
if (hash == -1)
return NULL;
}
#ifdef Py_GIL_DISABLED

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

Does this differ from PyDict_Contains()? Can we just call that?

Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c
PyObject *value;
Py_ssize_t ix;

#ifdef Py_GIL_DISABLED

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

This also looks like contains_known_hash

Copy link
Copy Markdown
Contributor Author

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

Or does contains_known_hash look like this? 🤔

DinoV force-pushed the nogil_dict_get_threadsafe branch from 54095de to af7ddb9 Compare February 16, 2024 00:12

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

DinoV force-pushed the nogil_dict_get_threadsafe branch from af7ddb9 to d608fb3 Compare February 21, 2024 00:44
DinoV merged commit 5407146 into python:main Feb 21, 2024
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
…id locking (python#115109)

Makes accessing a single element thread safe and typically lock free
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…id locking (python#115109)

Makes accessing a single element thread safe and typically lock free
DinoV deleted the nogil_dict_get_threadsafe branch May 31, 2024 18:23
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull request Jan 22, 2025
…id locking (python#115109)

Makes accessing a single element thread safe and typically lock free
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.

2 participants


Back | FazBrowse Home | New Git URL