Skip to content

Commit f220d83

Browse files
committed
add list free-threading tsan test to test_list.py
1 parent e36e314 commit f220d83

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lib/test/test_list.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import signal
22
import sys
33
import textwrap
4+
import threading
45
from test import list_tests, support
56
from test.support import cpython_only
7+
from test.support import threading_helper
68
from test.support.import_helper import import_module
79
from test.support.script_helper import assert_python_failure, assert_python_ok
810
import pickle
@@ -379,6 +381,33 @@ def foo(x):
379381

380382
self.assertEqual(foo(list(range(10))), 45)
381383

384+
@unittest.skipUnless(support.Py_GIL_DISABLED and
385+
support.check_sanitizer(thread=True),
386+
'this test can only possibly fail with GIL disabled')
387+
@threading_helper.reap_threads
388+
@threading_helper.requires_working_threading()
389+
def test_free_threading(self):
390+
def mutate(b, l):
391+
d = [None] * 100
392+
b.wait()
393+
394+
for _ in range(100):
395+
l.extend(d)
396+
del l[:]
397+
398+
NUM_THREADS = 10
399+
barrier = threading.Barrier(len(NUM_THREADS))
400+
threads = []
401+
l = []
402+
403+
for _ in range(NUM_THREADS):
404+
thread = threading.Thread(target=mutate, args=(barrier, l))
405+
406+
threads.append(thread)
407+
408+
with threading_helper.start_threads(threads):
409+
pass
410+
382411

383412
if __name__ == "__main__":
384413
unittest.main()

0 commit comments

Comments
 (0)