Ensuring idle task runs after vTaskDelete

jcwren wrote on Thursday, March 13, 2008:

If one wanted to restart a task by deleting it with vTaskDelete() followed by xTaskCreate(), is there a way to ensure the idle task gets run to clean up between the calls?

In this particular situation, I have a task that initializes a handful of variables at startup which control which of two devices the driver talks to.  The user can flip a switch to change which device is used.  The cleanest method at this particular time is to have the main control task stop and restart the driver task.  I just need (I think) to make sure the idle tasks gets run to clean up the TCBs and such.

Thanks,
–jc

adarkar9 wrote on Friday, March 14, 2008:

Here are some ways:

- Have the idle task create the driver task if it has been deleted.
- Have the idle task send a message to your main control task when it detects that the driver task has been deleted.
- Have the idle task give a semaphore every time it runs and have the main control task pend on the semaphore after deleting the driver task.

The last method is the most generic, but it does add extra overhead to the idle task.

jcwren wrote on Friday, March 14, 2008:

The last idea was the one I had already come up with, but I was hoping there was a less hackish way of doing this.

It would seem that if vTaskDelete() and xTaskCreate() are being used, there should be some way of enforcing the clean up.  Yes, sooner or later the idle task will run, but guaranteeing when is more difficult.

–jc

adarkar9 wrote on Friday, March 14, 2008:

The idle task calls the static function prvCheckTasksWaitingTermination() to finish deleting tasks.  Perhaps you could make this public and call it after you call vTaskDelete().  You must be careful not to do this from the task you deleted, though.  Of course, you’re not sticking to the API if you do this, but it is a more elegant solution.