heinbali01 wrote on Thursday, February 23, 2017:
Creating object from within a task ?
Objects ( instances of C++ classes ) can be created and used from within a task. In fact, after
vTaskStartScheduler() has been called, all code is running from within a task. Except ISR’s, who have their own life and rules.
Create a task from within an object ( i think wrappers are needed in this case)
That is also possible. Wrappers will make your code nicer, easier to read, but they’re not necessary.
When creating tasks ( from within an object, or wherever ), remember that you work on an embedded project, with limited resources: limited in CPU-speed, limited in memory.
When you start a modern browser on a laptop, it will easily create 7 processes, each process will create 16 threads, and the program will allocate e.g. 37 MB of RAM.
On the contrary, an embedded HTTP-server ( from FreeRTOS+TCP ) will run in a single task and allocate KB’s in stead of MB’s. Well, unless your hardware has external SDRAM.
Combine the task and boject ( 1 task correspnds to on object )
and the deletion of the one means the deletion of the other.
That’s a nice idea: each task (except Idle, that you do not own) is bound to an object, and when the object is deleted, its task will be terminated.
In another thread about C++, yesterday, I referred to Richard Damon’s C++ project
I wrote that
delete() must be redefined in order to use task-safe allocators. These allocators are defined in one of the
I often like the addition of C++ to embedded projects. The presence of constructors and destructors formalise important steps. Object-oriented thinking can make life easier.