-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-144356: fix data race in setiter_len() under no-gil
#144357
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix a data race in ``set_iterator.__length_hint__`` under ``Py_GIL_DISABLED``. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1056,7 +1056,8 @@ setiter_len(PyObject *op, PyObject *Py_UNUSED(ignored)) | |
| { | ||
| setiterobject *si = (setiterobject*)op; | ||
| Py_ssize_t len = 0; | ||
| if (si->si_set != NULL && si->si_used == si->si_set->used) | ||
| PySetObject *so = si->si_set; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here This is a different mechanism than the corresponding issue, so maybe something to address in another PR. But solving both together is something to consider. |
||
| if (so != NULL && si->si_used == FT_ATOMIC_LOAD_SSIZE_RELAXED(so->used)) | ||
| len = si->len; | ||
| return PyLong_FromSsize_t(len); | ||
| } | ||
|
|
||
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 means the threads will stop right after they have started. I would prefer the pattern that is used in some other tests in this file: set a constant
NUM_LOOPS(determined so that the test < 0.1 seconds, but there still is a decent number of mutations)