8000 gh-123471: Make concurrent iteration over itertools.repeat safe under free-threading by eendebakpt · Pull Request #131247 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-123471: Make concurrent iteration over itertools.repeat safe under free-threading #131247

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

Merged
merged 3 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make concurrent iterations over :class:`itertools.repeat` safe under free-threading.
10 changes: 7 additions & 3 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3630,10 +3630,14 @@ static PyObject *
repeat_next(PyObject *op)
{
repeatobject *ro = repeatobject_CAST(op);
if (ro->cnt == 0)
Py_ssize_t cnt = FT_ATOMIC_LOAD_SSIZE_RELAXED(ro->cnt);
if (cnt == 0) {
return NULL;
if (ro->cnt > 0)
ro->cnt--;
}
if (cnt > 0) {
cnt--;
FT_ATOMIC_STORE_SSIZE_RELAXED(ro->cnt, cnt);
}
return Py_NewRef(ro->element);
}

Expand Down
Loading
0