From 44e58d6038f130bdc263b4d63a556af1e460b9ba Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 20 Nov 2022 10:39:15 +1000 Subject: [PATCH] Fix some bugs with initialization of POSIX threads. --- CHANGES.md | 1 + miniaudio.h | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cdbbb7d7..66a8bc57 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ v0.11.12 - TBD ===================== * Fix a crash due to a race condition in the resource manager. * Fix a crash with some backends when rerouting the playback side of a duplex device. +* Fix some bugs with initialization of POSIX threads. v0.11.11 - 2022-11-04 diff --git a/miniaudio.h b/miniaudio.h index 104d0179..e468ec6d 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -15852,6 +15852,10 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority pthread_attr_t attr; if (pthread_attr_init(&attr) == 0) { int scheduler = -1; + + /* We successfully initialized our attributes object so we can assign the pointer so it's passed into pthread_create(). */ + pAttr = &attr; + if (priority == ma_thread_priority_idle) { #ifdef SCHED_IDLE if (pthread_attr_setschedpolicy(&attr, SCHED_IDLE) == 0) { @@ -15895,9 +15899,8 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority } } - if (pthread_attr_setschedparam(&attr, &sched) == 0) { - pAttr = &attr; - } + /* I'm not treating a failure of setting the priority as a critical error so not checking the return value here. */ + pthread_attr_setschedparam(&attr, &sched); } } }