From 77ad7174005e59321765b1a9ace3f20b5ab029f1 Mon Sep 17 00:00:00 2001 From: Reda Maher <52288047+RedaMaher@users.noreply.github.com> Date: Tue, 6 Oct 2020 03:06:51 +0200 Subject: [PATCH] Posix: Fix no task switching issue if a task ended its main function (#184) * Posix: Fix no task switching issue if a task ended When the main function of a task exits, no task switching happened. This is because all the remaining tasks are waiting on the condition variable. The fix is to trigger a task switch and mark the exiting task as "Dying" to be suspened and exited properly from the scheduler. * Posix: Assert and stop if the Task function returned * Posix: just assert if a task returned from its main function Co-authored-by: alfred gedeon --- portable/ThirdParty/GCC/Posix/port.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 7d7b5d887..7107a56f8 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -430,6 +430,13 @@ Thread_t *pxThread = pvParams; /* Call the task's entry point. */ pxThread->pxCode( pxThread->pvParams ); + /* A function that implements a task must not exit or attempt to return to + * its caller as there is nothing to return to. If a task wants to exit it + * should instead call vTaskDelete( NULL ). Artificially force an assert() + * to be triggered if configASSERT() is defined, so application writers can + * catch the error. */ + configASSERT( pdFALSE ); + return NULL; } /*-----------------------------------------------------------*/