summaryrefslogtreecommitdiffstats
path: root/Lib/test/lock_tests.py
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2023-09-26 11:57:25 (GMT)
committerGitHub <noreply@github.com>2023-09-26 11:57:25 (GMT)
commit0eb98837b60bc58e57ad3e2b35c6b0e9ab634678 (patch)
tree215ecf809bc7a23493ffd1419db302515c05d377 /Lib/test/lock_tests.py
parent2897142d2ec0930a8991af964c798b68fb6dcadd (diff)
downloadcpython-0eb98837b60bc58e57ad3e2b35c6b0e9ab634678.zip
cpython-0eb98837b60bc58e57ad3e2b35c6b0e9ab634678.tar.gz
cpython-0eb98837b60bc58e57ad3e2b35c6b0e9ab634678.tar.bz2
gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (#109629)
--------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/lock_tests.py')
-rw-r--r--Lib/test/lock_tests.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 0890ec8..e53e24b 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -330,6 +330,42 @@ class RLockTests(BaseLockTests):
lock.release()
self.assertRaises(RuntimeError, lock._release_save)
+ def test_recursion_count(self):
+ lock = self.locktype()
+ self.assertEqual(0, lock._recursion_count())
+ lock.acquire()
+ self.assertEqual(1, lock._recursion_count())
+ lock.acquire()
+ lock.acquire()
+ self.assertEqual(3, lock._recursion_count())
+ lock.release()
+ self.assertEqual(2, lock._recursion_count())
+ lock.release()
+ lock.release()
+ self.assertEqual(0, lock._recursion_count())
+
+ phase = []
+
+ def f():
+ lock.acquire()
+ phase.append(None)
+ while len(phase) == 1:
+ _wait()
+ lock.release()
+ phase.append(None)
+
+ with threading_helper.wait_threads_exit():
+ start_new_thread(f, ())
+ while len(phase) == 0:
+ _wait()
+ self.assertEqual(len(phase), 1)
+ self.assertEqual(0, lock._recursion_count())
+ phase.append(None)
+ while len(phase) == 2:
+ _wait()
+ self.assertEqual(len(phase), 3)
+ self.assertEqual(0, lock._recursion_count())
+
def test_different_thread(self):
# Cannot release from a different thread
lock = self.locktype()