From 1b258a4a00048e6ef7543b3892e00fd5a281d85e Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Wed, 26 Feb 2025 21:55:29 -0800 Subject: [PATCH] use ExitThread instead of TerminateThread Preferred in Windows, especially when we can't guarantee that we are able to perform a proper clean-up before terminating. Halt may be called with the Kill flag which indicates everything must shut down. This is the preferred approach in the Windows API. Another preferred option is to use WaitForSingleObject with a timeout, but Halt with the Kill flag is being called when the game is about to crash, so that's not a realistic option and may cause the program to hang indefinitely. --- src/arch/Threads/Threads_Win32.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/arch/Threads/Threads_Win32.cpp b/src/arch/Threads/Threads_Win32.cpp index 52d8ba970e..9c903e9d70 100644 --- a/src/arch/Threads/Threads_Win32.cpp +++ b/src/arch/Threads/Threads_Win32.cpp @@ -43,9 +43,16 @@ HANDLE Win32ThreadIdToHandle(uint64_t iID) return nullptr; } -void ThreadImpl_Win32::Halt(bool /*Kill*/) +void ThreadImpl_Win32::Halt(bool Kill) { - SuspendThread(ThreadHandle); + if (Kill) + { + ExitThread(0); // 0 indicates the thread was terminated + } + else + { + SuspendThread(ThreadHandle); + } } void ThreadImpl_Win32::Resume()