Add support for Cooperative Suspend when running on Mono

Informs mono runtime that Job System, Thread Pool or Content Load threads can wait when they are going idle between tasks.
This commit is contained in:
Wojtek Figat
2025-11-26 00:22:48 -08:00
parent cf048c9804
commit c8839b8587
5 changed files with 68 additions and 1 deletions

View File

@@ -2147,7 +2147,13 @@ bool InitHostfxr()
#endif
// Adjust GC threads suspending mode to not block attached native threads (eg. Job System)
// https://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/
#if USE_MONO_AOT_COOP
Platform::SetEnvironmentVariable(TEXT("MONO_THREADS_SUSPEND"), TEXT("coop"));
Platform::SetEnvironmentVariable(TEXT("MONO_SLEEP_ABORT_LIMIT"), TEXT("5000")); // in ms
#else
Platform::SetEnvironmentVariable(TEXT("MONO_THREADS_SUSPEND"), TEXT("preemptive"));
#endif
#if defined(USE_MONO_AOT_MODE)
// Enable AOT mode (per-platform)