Skip to content

Commit b7422f4

Browse files
authored
Merge pull request #1480 from Unity-Technologies/fix-1308216
Fix thread detach of reverse pinvoke (case 1308216)
2 parents 6714035 + b3b4894 commit b7422f4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mono/metadata/threads.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6392,7 +6392,7 @@ mono_threads_attach_coop_internal (MonoDomain *domain, gpointer *cookie, MonoSta
63926392
external = !(info = mono_thread_info_current_unchecked ()) || !mono_thread_info_is_live (info);
63936393

63946394
if (!mono_thread_internal_current ()) {
6395-
mono_thread_internal_attach (domain);
6395+
mono_thread_internal_attach (mono_get_root_domain ());
63966396

63976397
// #678164
63986398
mono_thread_set_state (mono_thread_internal_current (), ThreadState_Background);
@@ -6409,8 +6409,10 @@ mono_threads_attach_coop_internal (MonoDomain *domain, gpointer *cookie, MonoSta
64096409
}
64106410
}
64116411

6412-
if (orig != domain)
6412+
if (orig != domain) {
6413+
mono_thread_push_appdomain_ref (domain);
64136414
mono_domain_set_fast (domain, TRUE);
6415+
}
64146416

64156417
return orig;
64166418
}
@@ -6452,6 +6454,7 @@ mono_threads_detach_coop_internal (MonoDomain *orig, gpointer cookie, MonoStackD
64526454
mono_domain_unset ();
64536455
else
64546456
mono_domain_set_fast (orig, TRUE);
6457+
mono_thread_pop_appdomain_ref ();
64556458
}
64566459

64576460
if (mono_threads_is_blocking_transition_enabled ()) {

0 commit comments

Comments
 (0)