diff options
author | Edward Xu <xuxiangad@foxmail.com> | 2024-12-16 19:12:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 19:12:19 (GMT) |
commit | 4937ba54c0ff7cc4a83d7345d398b804365af2d6 (patch) | |
tree | 2411d7bcfeb5413114506b755f2eae981681d888 /Lib/test | |
parent | 1d276ec6f8403590a6a1a18c560ce75b9221572b (diff) | |
download | cpython-4937ba54c0ff7cc4a83d7345d398b804365af2d6.zip cpython-4937ba54c0ff7cc4a83d7345d398b804365af2d6.tar.gz cpython-4937ba54c0ff7cc4a83d7345d398b804365af2d6.tar.bz2 |
gh-127085: fix some data races in memoryview in free-threading (#127412)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_memoryview.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py index 96320eb..856e179 100644 --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -16,7 +16,8 @@ import pickle import struct from itertools import product -from test.support import import_helper +from test import support +from test.support import import_helper, threading_helper class MyObject: @@ -733,5 +734,28 @@ class OtherTest(unittest.TestCase): self.assertIsNone(wr()) +@threading_helper.requires_working_threading() +@support.requires_resource("cpu") +class RacingTest(unittest.TestCase): + def test_racing_getbuf_and_releasebuf(self): + """Repeatly access the memoryview for racing.""" + from multiprocessing.managers import SharedMemoryManager + from threading import Thread + + n = 100 + with SharedMemoryManager() as smm: + obj = smm.ShareableList(range(100)) + threads = [] + for _ in range(n): + # Issue gh-127085, the `ShareableList.count` is just a convenient way to mess the `exports` + # counter of `memoryview`, this issue has no direct relation with `ShareableList`. + threads.append(Thread(target=obj.count, args=(1,))) + + with threading_helper.start_threads(threads): + pass + + del obj + + if __name__ == "__main__": unittest.main() |