Skip to content

Commit fda856f

Browse files
[3.13] gh-142048: Fix lost gc allocations count on thread cleanup (GH… (#142506)
[3.13] gh-142048: Fix lost gc allocations count on thread cleanup (GH-142233) (cherry picked from commit 49b1fb4) Co-authored-by: Kevin Wang <[email protected]>
1 parent 813bcff commit fda856f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Python/pystate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,14 @@ PyThreadState_Clear(PyThreadState *tstate)
17431743

17441744
// Remove ourself from the biased reference counting table of threads.
17451745
_Py_brc_remove_thread(tstate);
1746+
1747+
// Flush the thread's local GC allocation count to the global count
1748+
// before the thread state is cleared, otherwise the count is lost.
1749+
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
1750+
_Py_atomic_add_int(&tstate->interp->gc.generations[0].count,
1751+
(int)tstate_impl->gc.alloc_count);
1752+
tstate_impl->gc.alloc_count = 0;
1753+
17461754
#endif
17471755

17481756
// Merge our queue of pointers to be freed into the interpreter queue.

0 commit comments

Comments
 (0)