diff --git a/Lib/test/test_free_threading/test_type.py b/Lib/test/test_free_threading/test_type.py index 6e750e0bc6084e..f7e4adf2e02ce8 100644 --- a/Lib/test/test_free_threading/test_type.py +++ b/Lib/test/test_free_threading/test_type.py @@ -375,6 +375,7 @@ def test_concurrent_setattr_deadlock(self): # dict mutex and waited for the type lock. # This is fairly difficult to trigger the race but this N seems to do # it at least sometimes. + type_freeze = import_helper.import_module("_testlimitedcapi").type_freeze N = 200 done = False @@ -401,6 +402,15 @@ def lister(): while not done: Base.__subclasses__() + def freezer(): + # gh-158194: Exercise type freezing concurrently with slot + # updates and competing stop-the-world requests. + barrier.wait() + for _ in range(10): + class Frozen: + pass + type_freeze(Frozen) + def basesetter(): nonlocal done barrier.wait() @@ -418,7 +428,7 @@ class B(A): # to keep the type lock and the stop-the-world mutex contended, which # is what gets the setters into the window where it happens. targets = (setter, setter, subclasser, subclasser, - lister, lister, basesetter) + lister, lister, basesetter, freezer) barrier = threading.Barrier(len(targets)) threads = [Thread(target=target) for target in targets] with threading_helper.start_threads(threads):