From 98c457ec4f4bb6da6cdc685badd8019f0635cf4e Mon Sep 17 00:00:00 2001 From: kurrutako Date: Wed, 25 Nov 2026 17:06:49 +0100 Subject: gta6rt: threads that fault together wait for the first one's cache write (RT-SESSION-CACHE-AT-EXIT) A boot ended with eight title threads faulting within a second. Each entered the filter; the ones after the first returned at once and went on to the title's filter, which can end the process during the write. The write now runs under std::call_once, so they wait for it. AI-assisted. Co-Authored-By: Claude Opus 5.5 --- runtime/src/main.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'runtime/src/main.cpp') diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 98e377f1c..d386de0cd 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -261,11 +262,16 @@ static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI title_set_unhandled_exception_filter( static LONG WINAPI save_caches_on_fatal_exception(EXCEPTION_POINTERS* info) { const DWORD code = info && info->ExceptionRecord ? info->ExceptionRecord->ExceptionCode : 0; if (code != EXCEPTION_STACK_OVERFLOW) { - std::fprintf(stderr, "[rt] unhandled exception 0x%08lx: writing the session pipeline cache before the " - "process ends\n", static_cast(code)); - rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs); - rt::d3d12::save_pipeline_caches_at_exit(kExitCacheWaitMs); - std::fflush(stderr); + // Several title threads can fault at once (measured: eight within a second). The first writes; the others + // wait here for it, so none of them reaches the title's filter, which may end the process, mid-write. + static std::once_flag once; + std::call_once(once, [code] { + std::fprintf(stderr, "[rt] unhandled exception 0x%08lx: writing the session pipeline cache before the " + "process ends\n", static_cast(code)); + rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs); + rt::d3d12::save_pipeline_caches_at_exit(kExitCacheWaitMs); + std::fflush(stderr); + }); } if (auto* title = reinterpret_cast( InterlockedCompareExchangePointer(&title_fatal_filter, nullptr, nullptr))) -- cgit v1.2.3