Unnatural task form

nobody wrote on Monday, May 15, 2006:

Hi, I think that endless-loop form of task function is somewhat weird.

Why not automatically put NULL and pointer to vTaskDelete on the stack of newly created task?

This way you get plain and simple void function as task code which may end-by-return…


nobody wrote on Monday, May 15, 2006:

Most tasks are implemented as an endless loop.  If you want the task to run just once, then probably not a good candidate for a task.  If you want the task to delete, just place vTaskDelete(NULL) at the end of the function and you have not wasted any stack.

nobody wrote on Monday, May 15, 2006:

Well, I will defend my point of view:

I didn’t mean to run task once. It is just more portable and safe (what happens now if u return from task?) to have the task cleaned up automatically. The four bytes (AVR) of data (16b NULL + pointer to vTaskDelete) is not much for ability to just “return” from task.

Maybe FreeRTOS author will answer this from professional’s point of view.

nobody wrote on Monday, May 15, 2006:

If this forum was like some of the others, you’d get rained on now.  The endless loop task structure is the way it is done in most if not all multitasking environments.  Certainly all I have ever seen.  It is just as “safe” as any other form.  Just follow the rules.  The rest of us don’t want the added overhead of support for those who don’t want to do it the way the documentation says it should be done.  If I were Richard, I wouldn’t waste my time arguing with you about this.

rtel wrote on Monday, May 15, 2006:

Hmm, I don’t want to sit on the fence too much, but I don’t really see it as a big issue.  It is just an implementation choice.

Placing a jump to a delete function on the return stack is valid and neat, but does require more stack (albeit a few bytes, remember FreeRTOS runs on some tiny processors).  I don’t see how this gets around having most tasks as an infinite loop however.

The current implementation will allow users to crash the code by running off the bottom of a task.  Doing so would show a lack of understanding of the system they were programming so I doubt this would be their only problem ;-)  There are lots of ways you can cause a crash, and as a small fast implementation FreeRTOS does not try to guard against them all.  Placing a vTaskDelete call outside of the loop is not a big issue, and more explicit of how you intend the task to function.

So I don’t have strong feelings either way.  FreeRTOS provides all the source code so you can make your application function however you wish by editing if you so desire.


jwestmoreland wrote on Monday, May 15, 2006:

I think I’m repeating here - but it seems that the functionality of what ‘nobody’ wants is already in FreeRTOS.  vTaskDelete() gives the ability asked for.

As Richard has stated - the source code is there.  In port.c - you can make the stack behave any way you want.  There are issues of both compiler (tool-sets) and the target MCU.  It doesn’t seem to be a very portable approach IMHO, but the source is there for you to modify as you wish.

As FreeRTOS runs on a lot of RAM constrained systems - I think (IMHO) that leaving the stack alone is the way to go vs. adding more args on the stack.

Just my 2 cents,
John W.