forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-127085: fix
memoryview->exports
race condition.
- Loading branch information
1 parent
3afb639
commit c7872cd
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import multiprocessing.shared_memory | ||
from threading import Thread | ||
import unittest | ||
|
||
from test.support import threading_helper | ||
|
||
|
||
class TestBase(unittest.TestCase): | ||
pass | ||
|
||
|
||
def do_race(): | ||
"""Repeatly access the memoryview for racing.""" | ||
n = 100 | ||
|
||
obj = multiprocessing.shared_memory.ShareableList("Uq..SeDAmB+EBrkLl.SG.Z+Z.ZdsV..wT+zLxKwdN\b") | ||
threads = [] | ||
for _ in range(n): | ||
threads.append(Thread(target=obj.count, args=(1,))) | ||
|
||
for t in threads: | ||
t.start() | ||
|
||
for t in threads: | ||
t.join() | ||
|
||
del obj | ||
|
||
|
||
@threading_helper.requires_working_threading() | ||
class TestMemoryView(TestBase): | ||
def test_racing_getbuf_and_releasebuf(self): | ||
do_race() | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters