From 017ac82d5965f70516f71dfded148fc663215968 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 7 Aug 2023 13:34:38 +0200 Subject: [PATCH] fix: race condition on mixer task handle (#3914) PR #3451 moved the start of the mixer task to a point in time where the task scheduler is already started (UI task). Before that change, the mixer task would be created before and effectively started after the task scheduler started. This introduces a race condition on `mixerTaskId.rtos_handle`, as the mixer scheduler might trigger before `xTaskCreateStatic()` returns and the task handle is assigned. This PR fixes the issue by delaying the start of the mixer scheduler until `xTaskCreateStatic()` returned and the task handler has been properly assigned. --- radio/src/tasks/mixer_task.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/radio/src/tasks/mixer_task.cpp b/radio/src/tasks/mixer_task.cpp index 962beea10..e406c77bc 100644 --- a/radio/src/tasks/mixer_task.cpp +++ b/radio/src/tasks/mixer_task.cpp @@ -60,9 +60,11 @@ void mixerTaskUnlock() void mixerTaskInit() { + mixerSchedulerInit(); RTOS_CREATE_MUTEX(mixerMutex); RTOS_CREATE_TASK(mixerTaskId, mixerTask, "mixer", mixerStack, MIXER_STACK_SIZE, MIXER_TASK_PRIO); + mixerSchedulerStart(); } bool mixerTaskStarted() @@ -147,9 +149,6 @@ TASK_FUNCTION(mixerTask) gyroInit(); #endif - mixerSchedulerInit(); - mixerSchedulerStart(); - while (!_mixer_exit) { int timeout = 0;