Skip to content

Commit 645c3f3

Browse files
committed
Run simplified finalizer logic when gc is disabled to allow child processes to complete
1 parent 85e0af0 commit 645c3f3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

mono/metadata/gc.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ mono_gc_finalize_notify (void)
760760
g_message ( "%s: prodding finalizer", __func__);
761761
#endif
762762

763-
if (mono_gc_is_null () || mono_gc_is_disabled())
763+
if (mono_gc_is_null ())
764764
return;
765765

766766
#ifdef HOST_WASM
@@ -928,6 +928,18 @@ finalizer_thread (gpointer unused)
928928
/* Register a hazard free queue pump callback */
929929
mono_hazard_pointer_install_free_queue_size_callback (hazard_free_queue_is_too_big);
930930

931+
/* if GC is disabled, we run no finalizer, but we still run mono_w32process_signal_finished
932+
on the finalizer thread, so that processes can exit. */
933+
if (mono_gc_is_disabled())
934+
{
935+
while (!finished)
936+
{
937+
mono_coop_sem_wait (&finalizer_sem, MONO_SEM_FLAGS_ALERTABLE);
938+
mono_w32process_signal_finished();
939+
}
940+
return 0;
941+
}
942+
931943
while (!finished) {
932944
/* Wait to be notified that there's at least one
933945
* finaliser to run
@@ -995,10 +1007,8 @@ mono_gc_init (void)
9951007

9961008
mono_gc_base_init ();
9971009

998-
if (mono_gc_is_disabled ()) {
1010+
if (mono_gc_is_disabled ())
9991011
gc_disabled = TRUE;
1000-
return;
1001-
}
10021012

10031013
#ifdef TARGET_WIN32
10041014
pending_done_event = CreateEvent (NULL, TRUE, FALSE, NULL);
@@ -1025,9 +1035,9 @@ mono_gc_cleanup (void)
10251035

10261036
if (mono_gc_is_null ())
10271037
return;
1028-
1038+
1039+
finished = TRUE;
10291040
if (!gc_disabled) {
1030-
finished = TRUE;
10311041
if (mono_thread_internal_current () != gc_thread) {
10321042
int ret;
10331043
gint64 start;

0 commit comments

Comments
 (0)