Skip to content

Commit dd56d89

Browse files
committed
Extend tests a little, add suppressions with links to GH issues.
1 parent ed7e8c7 commit dd56d89

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Lib/test/test_free_threading/test_iteration.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import threading
32
import unittest
43
from test import support
@@ -14,7 +13,7 @@
1413
NUMTHREADS = 2
1514
else:
1615
NUMITEMS = 100000
17-
NUMTHREADS = 3
16+
NUMTHREADS = 5
1817
NUMMUTATORS = 2
1918

2019
class ContendedTupleIterationTest(unittest.TestCase):
@@ -88,7 +87,10 @@ def mutator():
8887
replacement = (orig * 3)[NUMITEMS//2:]
8988
start.wait()
9089
while not endmutate.is_set():
91-
seq[:] = replacement
90+
seq.extend(replacement)
91+
seq[:0] = orig
92+
seq.__imul__(2)
93+
seq.extend(seq)
9294
seq[:] = orig
9395
def worker():
9496
items = []
@@ -124,7 +126,7 @@ def assert_iterator_results(self, results, expected):
124126
for item in extra_items:
125127
self.assertEqual((item - expected.start) % expected.step, 0)
126128

127-
# Long iterators are not thread-safe yet.
129+
# Long range iterators are not thread-safe yet.
128130
# class ContendedLongRangeIterationTest(ContendedTupleIterationTest):
129131
# def make_testdata(self, n):
130132
# return range(0, sys.maxsize*n, sys.maxsize)

Objects/listobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ list_repeat_lock_held(PyListObject *a, Py_ssize_t n)
784784
_Py_RefcntAdd(*src, n);
785785
*dest++ = *src++;
786786
}
787-
787+
// TODO: _Py_memory_repeat calls are not safe for shared lists in
788+
// GIL_DISABLED builds. (See issue #129069)
788789
_Py_memory_repeat((char *)np->ob_item, sizeof(PyObject *)*output_size,
789790
sizeof(PyObject *)*input_size);
790791
}
@@ -920,7 +921,7 @@ list_ass_slice_lock_held(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyO
920921
Py_ssize_t tail;
921922
tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *);
922923
// TODO: these memmove/memcpy calls are not safe for shared lists in
923-
// GIL_DISABLED builds.
924+
// GIL_DISABLED builds. (See issue #129069)
924925
memmove(&item[ihigh+d], &item[ihigh], tail);
925926
if (list_resize(a, Py_SIZE(a) + d) < 0) {
926927
memmove(&item[ihigh], &item[ihigh+d], tail);
@@ -935,7 +936,7 @@ list_ass_slice_lock_held(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyO
935936
goto Error;
936937
item = a->ob_item;
937938
// TODO: these memmove/memcpy calls are not safe for shared lists in
938-
// GIL_DISABLED builds.
939+
// GIL_DISABLED builds. (See issue #129069)
939940
memmove(&item[ihigh+d], &item[ihigh],
940941
(k - ihigh)*sizeof(PyObject *));
941942
}
@@ -1021,6 +1022,8 @@ list_inplace_repeat_lock_held(PyListObject *self, Py_ssize_t n)
10211022
for (Py_ssize_t j = 0; j < input_size; j++) {
10221023
_Py_RefcntAdd(items[j], n-1);
10231024
}
1025+
// TODO: _Py_memory_repeat calls are not safe for shared lists in
1026+
// GIL_DISABLED builds. (See issue #129069)
10241027
_Py_memory_repeat((char *)items, sizeof(PyObject *)*output_size,
10251028
sizeof(PyObject *)*input_size);
10261029
return 0;

Tools/tsan/suppressions_free_threading.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ race:set_allocator_unlocked
1818
# https://gist.github.com/swtaarrs/08dfe7883b4c975c31ecb39388987a67
1919
race:free_threadstate
2020

21-
2221
# These warnings trigger directly in a CPython function.
2322

2423
race_top:assign_version_tag
2524
race_top:new_reference
2625
race_top:_multiprocessing_SemLock_acquire_impl
27-
race_top:list_get_item_ref
2826
race_top:_Py_slot_tp_getattr_hook
2927
race_top:add_threadstate
3028
race_top:dump_traceback
@@ -46,3 +44,12 @@ race_top:set_default_allocator_unlocked
4644

4745
# https://gist.github.com/mpage/6962e8870606cfc960e159b407a0cb40
4846
thread:pthread_create
47+
48+
# Range iteration is not thread-safe yet (issue #129068)
49+
race_top:rangeiter_next
50+
51+
# List resizing happens through different paths ending in memcpy or memmove
52+
# (for efficiency), which will probably need to rewritten as explicit loops
53+
# of ptr-sized copies to be thread-safe. (Issue #129069)
54+
race:list_ass_slice_lock_held
55+
race:list_inplace_repeat_lock_held

0 commit comments

Comments
 (0)