When To Use Static Tasks

Hi,

Most of my projects are for simple real-time systems where tasks are started, but never deleted. They must persist through the operation of the device.

I usually use the default task named Monitor Task, then the ST Touch GFX GUI task and then various other tasks such as Ethernet/WifFi, and their interface tasks, and a real-time hi priority process control task, timer timer triggered using deferred interrupts, usually using notification, not sem’s.

In all cases these tasks must run continuously.

My policy has been if a task is going to run forever make it static. This makes debugging easier because the task stack and buffer are at fixed locations which I can optimise in terms of which memory and MPU settings to use. And I know exactly where they are. This also takes the heap out of the mix as a potential problem causing feature.

I also do the same for queues, semaphores etc.

On the odd occasion I have a number of transient tasks which are heavy memory users and that can be deleted on completion I use the dynamic versions for these.

Memory shortage is not usually an issue as I am generally using hi end processors with plenty of RAM and external ram.

My question:

  • Is my policy sound or should I be considering other factors?
  • Have you any guidelines or recommendations on this issue.

Kind Regards
Rob

Yes. That is a very sound strategy.

The only other thing to say is, knowing your target domain (the kind of device/application you are building) provides the insight to know which tasks must be static and which may be transitory when you do reach resource limits.

So:
Know your requirements up front.
Plan estimated resources.
Early optimization is likely to optimize the wrong thing.

Lastly, don’t be afraid to throw out the prototype!

I use a similar system to you, and virtually ALL my tasks are static, as well as Queue, Semaphores, Mutexes and the like.

In fact, using my Wrappers, my tasks are global C++ objects that are automatically created at program startup time, so features can be added by just linking in new modules into the program and main is often just a call to the scheduler startup function.

1 Like

Hi,

Thanks for that.

I’m knee-deep in prototypes so I get what you mean.

Kind Regards
Rob

Hi Richard,

Thanks for that.

Kind Regards
Rob