Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Lib/test/test_free_threading/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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):
Expand Down
Loading