From 97c1046104bcf6b3ef9754cb899ac97cc6df157c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 15 Oct 2023 21:59:12 +0200 Subject: [PATCH] Add assertions to ensure that `thread_init` is successful Ensure that `pthread_create`/`CreateThread` are successful. --- src/base/system.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index cb59a29bf..1bd0b64a7 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -824,16 +824,14 @@ void *thread_init(void (*threadfunc)(void *), void *u, const char *name) #if defined(CONF_PLATFORM_MACOS) && defined(__MAC_10_10) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0); #endif - int result = pthread_create(&id, &attr, thread_run, data); - if(result != 0) - { - dbg_msg("thread", "creating %s thread failed: %d", name, result); - return 0; - } + dbg_assert(pthread_create(&id, &attr, thread_run, data) == 0, "pthread_create failure"); return (void *)id; } #elif defined(CONF_FAMILY_WINDOWS) - return CreateThread(NULL, 0, thread_run, data, 0, NULL); + HANDLE thread = CreateThread(nullptr, 0, thread_run, data, 0, nullptr); + dbg_assert(thread != nullptr, "CreateThread failure"); + // TODO: Set thread name using SetThreadDescription (would require minimum Windows 10 version 1607) + return thread; #else #error not implemented #endif