Skip to content
Prev Previous commit
Reduce readers in test_racing_join_replace to 10, use Event to synchr…
…onize, and perform multiple joins per loop to increase chance of repro without synchronization
  • Loading branch information
MojoVampire committed May 22, 2024
commit 254a5a51721e6ae55f85c5c4f412f7b4d2190783
13 changes: 7 additions & 6 deletions Lib/test/test_free_threading/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ def test_racing_join_replace(self):
'''
l = [*'abcdefg']
MAX_ORDINAL = 1_000
READERS = 20
READERS = 10
done_event = Event()

def writer_func():
for i, c in zip(cycle(range(len(l))),
map(chr, range(128, MAX_ORDINAL))):
l[i] = c
del l[:] # Empty list to tell readers to exit
done_event.set()

def reader_func():
while True:
empty = not l
while not done_event.is_set():
''.join(l)
''.join(l)
''.join(l)
''.join(l)
if empty:
break

writer = Thread(target=writer_func)
readers = []
Expand Down