During enumerate.reduce there is an unprotected read of ->en_index
import itertools
import threading
en = enumerate(itertools.count()) # infinite inner iterator: next() never ends
stop = threading.Event()
def advance():
while not stop.is_set():
next(en) # enum_next: atomic write of en_index
def read():
while not stop.is_set():
en.__reduce__() # enum_reduce: plain read of en_index
threads = [threading.Thread(target=advance), threading.Thread(target=read)]
for t in threads:
t.start()
threading.Event().wait(2.0)
stop.set()
for t in threads:
t.join()
Bug report
Bug description:
During enumerate.reduce there is an unprotected read of
->en_indexcpython/Objects/enumobject.c
Line 283 in bc2fd44
TSAN flagged this, likely not a high impact python issue though
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs