File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -1815,16 +1815,23 @@ PyThreadState_Clear(PyThreadState *tstate)
18151815 struct _Py_freelists * freelists = _Py_freelists_GET ();
18161816 _PyObject_ClearFreeLists (freelists , 1 );
18171817
1818+ // Flush the thread's local GC allocation count to the global count
1819+ // before the thread state is cleared, otherwise the count is lost.
1820+ _PyThreadStateImpl * tstate_impl = (_PyThreadStateImpl * )tstate ;
1821+ _Py_atomic_add_int (& tstate -> interp -> gc .young .count ,
1822+ (int )tstate_impl -> gc .alloc_count );
1823+ tstate_impl -> gc .alloc_count = 0 ;
1824+
18181825 // Merge our thread-local refcounts into the type's own refcount and
18191826 // free our local refcount array.
1820- _PyObject_FinalizePerThreadRefcounts (( _PyThreadStateImpl * ) tstate );
1827+ _PyObject_FinalizePerThreadRefcounts (tstate_impl );
18211828
18221829 // Remove ourself from the biased reference counting table of threads.
18231830 _Py_brc_remove_thread (tstate );
18241831
18251832 // Release our thread-local copies of the bytecode for reuse by another
18261833 // thread
1827- _Py_ClearTLBCIndex (( _PyThreadStateImpl * ) tstate );
1834+ _Py_ClearTLBCIndex (tstate_impl );
18281835#endif
18291836
18301837 // Merge our queue of pointers to be freed into the interpreter queue.
You can’t perform that action at this time.
0 commit comments