anonymous wrote on Wednesday, April 29, 2009:
Each time I see people asking how many tasks they can create, I wonder whether it would be possible to statically initialize all the objects in FreeRTOS at compilation time.
It would be possible to declare a task as
TASK(pvCreatedTask, pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority);
and register it with the scheduler using
instead of calling xTaskCreate. xTaskRegister would do the classical initialization in the existing pre-allocated space.
Note that there is no obligation to declare the TASK macro with all the parameters I used; keeping pvCreatedTask and usStackDepth could be enough information for the macro.
This way, once the code compiles and links, you *know* for sure that you get enough space in memory for your task to be created (provided you got the stack size right), and xTaskRegister could not fail unless the task has already been registered. No dynamic allocation would be needed at scheduler start time (as even the idle task could be created this way), and the task name could even be kept in read-only memory (it could be copied onto the newly allocated stack space if a task is dynamically created using xTaskCreate, which I don’t propose to remove of course).
Doing the same with every kind of objects (queues, semaphores, mutexes) would probably remove every need of dynamic allocation in many use cases. If it became the preferred way of creating objects, we would not see those questions anymore (their frequency hints that this is a problem for many people).