resource wasted on task delete and create

sergiosider wrote on Friday, January 15, 2010:

Dear All & Richard,

I am using FreeRTOS for a while, and now I bumped into a problem that I need help to figure out:

On an MP3 application, I have the following task:

void vFADERTask (void* pvParameters)
char STEP;
vTaskDelay(60 / portTICK_RATE_MS);

FADERTaskHandle = NULL;


and, in another part of the program:

//create the Fader Task
if (FaderTaskHandle==NULL) {
if (xTaskCreate( vFADERTask, (signed portCHAR*) “Fader”, 64, NULL, 2, &FaderTaskHandle) != pdTRUE) DEBUG_PRINT(“CANT CREATE TASK!!!”);
} else {
DEBUG_PRINT(“Fader task running!”);

Here’s what happens:

It’s working fine, until I call it for aproximately 10 times…(plenty of time before each call, so no overlaps)
Then the code to create the task returns != pdTRUE… as there are no resources available

Do I have to clean up anything beyond calling vTaskDelete ?

another ‘parallel’ thing I noticed is that the Task Handle does not get NULLed by TaskDelete, so I had do it manually (is this a potential problem? so the task could be created before actually deleted ?)

Thank you very much!
Sergio P. Sider

edwards3 wrote on Friday, January 15, 2010:

Is the idle task getting any time to execute? The idle task frees up some of the resources after a task delete.

sergiosider wrote on Friday, January 15, 2010:

Yes… in my case, it’s fading out a music that is playing… I was commanding with the keyboard to fade out a music at a time… so there is plenty of time in theory…

sergiosider wrote on Friday, January 15, 2010:

Well, I think I may have found the problem, although did not test it:

I am not letting the Idle task run…. because all of my other task are higher priority and not all uses a taskdelay, only taskYIELD or not at all… so if I understood it, if I not call a vTaskDelay inside a higher priority task or something like that, the idle task never gets a chance to run… is that correct ?

richard_damon wrote on Friday, January 15, 2010:

Just calling taskYIELD will not let any lower priority tasks run (so depending on your task setup, more than the Idle task might get starved). You don’t need to use just vTaskDelay, a wait on a Queue (including semaphores and Mutexs) with a non-zero max delay parameter can also give time to lower priority tasks (assuming the task at least sometime gets to the Queue when it isn’t ready). A task that is designed to use “All remaining available CPU bandwidth” needs to be at the lowest priority that needs to be run.

richard_damon wrote on Friday, January 15, 2010:

A second comment, If you are going to be creating and deleting this task multiple times, and each creation will be doing the same thing, and you don’t need a variable number of them at once (which looks like it fits this case), it may be better to create the task once, and have it wait for a semaphore to tell it to start, it does its stuff, and then goes back, reinitialize itself and waits on the semaphore again.

sergiosider wrote on Saturday, January 16, 2010:

Thanks Richard…
I wasn’t letting the idle task run at all… one of my tasks was using taskYIELD only, and other was nothing at all… (the remaining tasks were ok, either using mutexes/semaphores and delays).

I actually implemented the “problematic” task in a run once task with semaphore (as you suggested).

Thanks again!