-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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: Dictionary global version counter should use atomic increments #114568
Conversation
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
@@ -209,8 +209,14 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) { | |||
#define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS) | |||
#define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1) | |||
|
|||
#ifdef Py_GIL_DISABLED | |||
#define DICT_NEXT_VERSION(INTERP) \ | |||
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT) |
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 is fine for now, especially in the interest of getting to the point where we can run the test suite with the GIL disabled, but we will want to avoid contention on the global version counter.
The strategy in nogil
and nogil-3.12
was to reserve something like the next 256 versions (atomically) and then serve the next version requests from thread-local state.
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.
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.
Oh, nice!
…increments (python#114568) Dictionary global version counter should use atomic increments
Dictionary global version counter should use atomic increments on free-threaded builds
dict
objects thread-safe in--disable-gil
builds #112075