@@ -324,6 +324,23 @@ merge_all_queued_objects(PyInterpreterState *interp, struct collection_state *st
324324 HEAD_UNLOCK (& _PyRuntime );
325325}
326326
327+ static void
328+ process_delayed_frees (PyInterpreterState * interp )
329+ {
330+ // In STW status, we can observe the latest write sequence by
331+ // advancing the write sequence immediately.
332+ _Py_qsbr_advance (& interp -> qsbr );
333+ _PyThreadStateImpl * current_tstate = (_PyThreadStateImpl * )_PyThreadState_GET ();
334+ _Py_qsbr_quiescent_state (current_tstate -> qsbr );
335+ HEAD_LOCK (& _PyRuntime );
336+ PyThreadState * tstate = interp -> threads .head ;
337+ while (tstate != NULL ) {
338+ _PyMem_ProcessDelayed (tstate );
339+ tstate = (PyThreadState * )tstate -> next ;
340+ }
341+ HEAD_UNLOCK (& _PyRuntime );
342+ }
343+
327344// Subtract an incoming reference from the computed "gc_refs" refcount.
328345static int
329346visit_decref (PyObject * op , void * arg )
@@ -1006,6 +1023,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state)
10061023 _PyEval_StopTheWorld (interp );
10071024 // merge refcounts for all queued objects
10081025 merge_all_queued_objects (interp , state );
1026+ process_delayed_frees (interp );
10091027
10101028 // Find unreachable objects
10111029 int err = deduce_unreachable_heap (interp , state );
0 commit comments