Skip to content

Commit c00b965

Browse files
committed
add blurb file
1 parent 104b4e6 commit c00b965

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

Lib/test/test_free_threading/test_gc.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def evil():
9595
thread.join()
9696

9797
def test_set_threshold(self):
98-
# GH-148613: Setting the GC threshold from another thread could causes
98+
# GH-148613: Setting the GC threshold from another thread could cause a
9999
# race between the `gc_should_collect` and `gc_set_threshold` functions.
100100
NUM_THREADS = 8
101101
NUM_ITERS = 100_000
@@ -115,12 +115,14 @@ def setter():
115115
for i in range(NUM_ITERS):
116116
gc.set_threshold(100 + (i % 100), 10 + (i % 10), 10 + (i % 10))
117117

118-
threads = [Thread(target=allocator) for _ in range(NUM_THREADS - 1)]
119-
threads.append(Thread(target=setter))
120-
for t in threads:
121-
t.start()
122-
for t in threads:
123-
t.join()
118+
old_threshold = gc.get_threshold()
119+
try:
120+
threads = [Thread(target=allocator) for _ in range(NUM_THREADS - 1)]
121+
threads.append(Thread(target=setter))
122+
with threading_helper.start_threads(threads):
123+
pass
124+
finally:
125+
gc.set_threshold(*old_threshold)
124126

125127

126128
if __name__ == "__main__":
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a data race in the free-threaded build between :func:`gc.set_threshold`
2+
and garbage collection scheduling during object allocation.

0 commit comments

Comments
 (0)