Repository navigation
process shim: the game thread that ends a run no longer exits the process before gta6rt finishes - #4043
process shim: the game thread that ends a run no longer exits the process before gta6rt finishes#4043AAyberkU wants to merge 1 commit into
Conversation
…cess before gta6rt finishes end_run signalled g_done and only then read g_running. run_entry wakes on g_done, closes it and clears g_running, so the game thread could read false and take the "run is already over" path: ExitProcess with the game's code while main.cpp was still printing "game exited with code N", reporting unimplemented imports, writing the trace "exit" event and cleaning up TLS clones. The exit code stayed right, but the lost line made run_startup_cmdline and the other checks that look for it flaky. end_run now reads g_running before it signals. g_running is set before the game thread starts and is cleared only after g_exited is claimed and g_done is set, so a read taken before the CAS is true for any thread that ends a live run. The exit during host shutdown (no run active) still calls ExitProcess, and so does an exit with no run started, which an "always park the CAS winner" fix would have hung. process_cmdline_test runs 50 entry points that return 77 on one CPU and fails (exit 77) without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kam471
left a comment
There was a problem hiding this comment.
Tested b6299c9d on Windows 11, MSVC 19.44.35228 + Ninja, RelWithDebInfo.
process_cmdline_test.exe-> exit 0; its new end-of-run block runs 50 entry-point returns with the process affinity pinned to one CPU; the existing command-line checks still pass.- Repeated the whole test 10 times (500 run-end iterations): 0 failures.
ctest -R process_cmdline-> 1/1 passed, 0.79 s.
The fix reads g_running before SetEvent(g_done), closing the window where run_entry could clear it and the game thread would take the ExitProcess path while main.cpp was still printing/cleaning up. Parking on the observed value is the right minimal change; no game files, no blocker.
|
Tested b6299c9 on Windows 11 24H2 (26100), MSVC 19.44 RelWithDebInfo + Ninja: pass. I found the same race independently while reproducing TEST-874 (comment in #3918), with the same two-line fix, so this is also a measurement of it:
One nit: 77 is the code this tree uses for SKIP ( No game files. AI-assisted (Claude). |
Flyander
left a comment
There was a problem hiding this comment.
Reviewed at b6299c9. The change keeps the host process alive until the runtime's completion signal is observed; I found no additional blocking issue beyond the existing comment about the test's return code. The PR reports 1,200 concurrent process runs and 480 repeated CTest executions passing on Windows.
|
Tested
AI-assisted (Claude). No game files. |
|
Tested b6299c9 (merged onto main aa2988c) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass
AI-assisted (Claude). |
Claimed in the coordination issue as: #3918 (comment) (new RT item)
What and why
end_run(runtime/shims/process.cpp) signalledg_doneand only then readg_running.run_entrywakes ong_done, closes its handles and setsg_running = false, so the game thread that ended the run could readfalseand take the "run is already over" path, callingExitProcesswhilemain.cppwas still finishing. That lost thegame exited with code Nline,report_called_unimplemented(), the traceexitevent andcleanup_tls_clones(). The exit code stayed right, butcheck_startup_cmdline.cmake,check_loaded_*.cmakeandcheck_game_dir.cmakerequire that line, so their tests failed now and then.The fix reads
g_runningbefore signalling. It is set before the game thread is created and cleared only afterg_exitedis claimed andg_doneis set, so the snapshot istruefor any thread that ends a live run. The "exit during host shutdown" path (no run active) still callsExitProcess, and so does an exit before any run started. (Making the CAS winner always park would have hung that case.)process_cmdline_test(already registered as theprocess_cmdlinectest, soruntime/CMakeLists.txtis untouched) gains a regression check: pinned to one CPU, 50run_entrycalls of an entry point that returns 77, with aSleep(1)after each. Without the fix the test process exits with code 77 on the first one.Tested
Windows 11 Pro, VS2022 MSVC 14.44.35207, CMake 3.31.6, Ninja, RelWithDebInfo. CPU only: no GPU tests, no game files.
process_cmdline_testwith the new check,main'send_run: failed 20 of 20 runs (exit 77). With the fix: passed 200 of 200.run_startup_cmdline,run_tiny_async,run_tiny_gdk_load,run_tiny_bundled_load,run_tiny_game_dir: onmain, 1 failure (run_startup_cmdline, missing "game exited" line) in 200 runs. With the fix,ctest --repeat until-fail:200passed all 1000 runs.ctest --test-dir <build> --output-on-failure: 54/54 passed (six skip without the retail package or a GPU: shader_library_corpus, bink_decode, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio; gameinput is disabled without SDL3).process.cppneargame_exit/run_entry, notend_run; the new test block sits at the end ofmain, away from the hunks of Runtime: RtlPcToFileHeader for a mapped image's own imports (static-CRT C++ exceptions) #1839, Runtime: the mapped executable's module identity (GetModuleHandle/Ex, GetModuleFileName, GetProcAddress) #2075 and Runtime: expose the mapped title's full path through CRT program-path imports #2861.AI-assisted (Claude Code); the runs above were done on this branch.
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)🤖 Generated with Claude Code