From 2f73eaa803f91f8332b5c8b047ba03a1210c9a80 Mon Sep 17 00:00:00 2001 From: Eksan0325 <853757993@qq.com> Date: Thu, 11 Jun 2026 15:41:14 +0800 Subject: [PATCH] fix(win32): detect CreateThread failure and pass correct handle to SetThreadPriority Previously, osal_thread_create checked the wrong handle value, so thread creation failures were reported as success. Also, osal_thread_create_rt passed the handle pointer instead of the thread HANDLE to SetThreadPriority, so real-time priority was never applied. Fixes #977 --- .gitignore | 1 + osal/win32/osal.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b905807..b3c72d6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ install /doc/html tags .vscode +.vs diff --git a/osal/win32/osal.c b/osal/win32/osal.c index 3297aa6..d4cb3a3 100644 --- a/osal/win32/osal.c +++ b/osal/win32/osal.c @@ -132,8 +132,10 @@ void osal_free(void *ptr) int osal_thread_create(void *thandle, int stacksize, void *func, void *param) { - *(OSAL_THREAD_HANDLE *)thandle = CreateThread(NULL, stacksize, func, param, 0, NULL); - if (!thandle) + HANDLE thread; + thread = CreateThread(NULL, (SIZE_T)stacksize, (LPTHREAD_START_ROUTINE)func, param, 0, NULL); + *(OSAL_THREAD_HANDLE*)thandle = thread; + if (thread == NULL) { return 0; } @@ -142,11 +144,13 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param) int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) { + HANDLE thread; int ret; ret = osal_thread_create(thandle, stacksize, func, param); if (ret) { - ret = SetThreadPriority(thandle, THREAD_PRIORITY_TIME_CRITICAL); + thread = *(OSAL_THREAD_HANDLE*)thandle; + ret = SetThreadPriority(thread, THREAD_PRIORITY_TIME_CRITICAL); } return ret; }