Skip to content

Commit 4c72dae

Browse files
test: add regression test
1 parent 6f175ed commit 4c72dae

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/test/test_free_threading/test_collections.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import threading
12
import unittest
2-
from collections import deque
3+
from collections import Counter, deque
34
from copy import copy
45
from test.support import threading_helper
56

@@ -49,5 +50,21 @@ def mutate():
4950
)
5051

5152

53+
class TestCounter(unittest.TestCase):
54+
def test_update_concurrent(self):
55+
# gh-151633: concurrent Counter.update calls must not cause use-after-free
56+
# under free-threading.
57+
NTHREADS = 4
58+
PER_THREAD = 5000
59+
c = Counter()
60+
data = ['x'] * PER_THREAD
61+
threads = [threading.Thread(target=c.update, args=(data,))
62+
for _ in range(NTHREADS)]
63+
for t in threads:
64+
t.start()
65+
for t in threads:
66+
t.join()
67+
68+
5269
if __name__ == "__main__":
5370
unittest.main()

0 commit comments

Comments
 (0)