Skip to content

Commit 4575fb9

Browse files
authored
gh-158194: Exercise type freezing in concurrent setattr deadlock test (#161655)
1 parent 1ce279e commit 4575fb9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎Lib/test/test_free_threading/test_type.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def test_concurrent_setattr_deadlock(self):
375375
# dict mutex and waited for the type lock.
376376
# This is fairly difficult to trigger the race but this N seems to do
377377
# it at least sometimes.
378+
type_freeze = import_helper.import_module("_testlimitedcapi").type_freeze
378379
N = 200
379380
done = False
380381

@@ -401,6 +402,15 @@ def lister():
401402
while not done:
402403
Base.__subclasses__()
403404

405+
def freezer():
406+
# gh-158194: Exercise type freezing concurrently with slot
407+
# updates and competing stop-the-world requests.
408+
barrier.wait()
409+
for _ in range(10):
410+
class Frozen:
411+
pass
412+
type_freeze(Frozen)
413+
404414
def basesetter():
405415
nonlocal done
406416
barrier.wait()
@@ -418,7 +428,7 @@ class B(A):
418428
# to keep the type lock and the stop-the-world mutex contended, which
419429
# is what gets the setters into the window where it happens.
420430
targets = (setter, setter, subclasser, subclasser,
421-
lister, lister, basesetter)
431+
lister, lister, basesetter, freezer)
422432
barrier = threading.Barrier(len(targets))
423433
threads = [Thread(target=target) for target in targets]
424434
with threading_helper.start_threads(threads):

0 commit comments

Comments
 (0)