mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
gh-127085: fix some data races in memoryview in free-threading (#127412)
This commit is contained in:
parent
1d276ec6f8
commit
4937ba54c0
3 changed files with 52 additions and 8 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue