GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-112075: Iterating a dict shouldn't require locks by DinoV · Pull Request #115108 · python/cpython Conversation
|
I was worried some crazy person might be using these things to distribute work across threads :P. I'm happy to make relax the guarantees and see how that goes. I suppose if that ever becomes an issue we can deal with it then :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0dd1a06 to
3c03084
Compare
| #endif | ||
|
|
||
| #ifndef Py_GIL_DISABLED |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| #endif | |
| #ifndef Py_GIL_DISABLED | |
| #else /* Py_GIL_DISABLED */ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return NULL; | ||
| } | ||
|
|
||
| #endif |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| #endif | |
| #endif /* Py_GIL_DISABLED */ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A few code style comments below
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #ifdef Py_GIL_DISABLED | ||
| if (has_unique_reference(result)) { | ||
| #else | ||
| if (Py_REFCNT(result) == 1) { | ||
| #endif |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
has_unique_reference already has special cases for Py_GIL_DISABLED and the default build:
| #ifdef Py_GIL_DISABLED | |
| if (has_unique_reference(result)) { | |
| #else | |
| if (Py_REFCNT(result) == 1) { | |
| #endif | |
| if (has_unique_reference(result)) { |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (values == NULL) | ||
| goto concurrent_modification; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think the preferred style is to always include braces in new C code
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (i >= used) | ||
| goto fail; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Even though we hold the lock here we may still lose a race against | ||
| // a lock-free iterator, therefore we may end up retrying our iteration. | ||
| retry: | ||
| start_pos = i = _Py_atomic_load_ssize_relaxed(&di->di_pos); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the wrappers from pycore_pyatomic_ft_wrappers.h to reduce the number of #ifdef statements.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
e2a13a2 to
0941e62
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but I think it'd be better if acquire_key_value follows the -1/0 convention. The comment above acquire_key_value would need to be updated too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| static int | ||
| acquire_key_value(PyObject **key_loc, PyObject *value, PyObject **value_loc, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Also here: -1 for error and 0 for success
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0941e62 to
a1d7718
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.