Skip to content
Merged
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
11 changes: 9 additions & 2 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,16 +1765,23 @@ PyThreadState_Clear(PyThreadState *tstate)
struct _Py_freelists *freelists = _Py_freelists_GET();
_PyObject_ClearFreeLists(freelists, 1);

// Flush the thread's local GC allocation count to the global count
// before the thread state is cleared, otherwise the count is lost.
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
_Py_atomic_add_int(&tstate->interp->gc.young.count,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is less common perhaps it's ok to allow the global GC count to go negative here? The compare-and-exchange loop is more accurate though, I can update to use that if preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think going negative here is fine

(int)tstate_impl->gc.alloc_count);
tstate_impl->gc.alloc_count = 0;

// Merge our thread-local refcounts into the type's own refcount and
// free our local refcount array.
_PyObject_FinalizePerThreadRefcounts((_PyThreadStateImpl *)tstate);
_PyObject_FinalizePerThreadRefcounts(tstate_impl);

// Remove ourself from the biased reference counting table of threads.
_Py_brc_remove_thread(tstate);

// Release our thread-local copies of the bytecode for reuse by another
// thread
_Py_ClearTLBCIndex((_PyThreadStateImpl *)tstate);
_Py_ClearTLBCIndex(tstate_impl);
#endif

// Merge our queue of pointers to be freed into the interpreter queue.
Expand Down
Loading