Skip to content
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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