mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
gh-123471: Make concurrent iteration over itertools.repeat safe under free-threading (#131247)
This commit is contained in:
parent
5863cd70b8
commit
9d127e83b9
2 changed files with 8 additions and 3 deletions
|
|
@ -0,0 +1 @@
|
||||||
|
Make concurrent iterations over :class:`itertools.repeat` safe under free-threading.
|
||||||
|
|
@ -3628,10 +3628,14 @@ static PyObject *
|
||||||
repeat_next(PyObject *op)
|
repeat_next(PyObject *op)
|
||||||
{
|
{
|
||||||
repeatobject *ro = repeatobject_CAST(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;
|
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);
|
return Py_NewRef(ro->element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue