Why are task names mutable?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why are task names mutable?

Jump to solution
899 Views
sam_
Contributor III

I am creating a task with _task_create_blocked which takes a task_template structure.  One of the parameters for the structure is a task name character array.  Is there a particular reason why this is a "char _PTR" instead of a "const char _PTR"?  Does MQX modify my task name?

Tags (3)
0 Kudos
1 Solution
725 Views
soledad
NXP Employee
NXP Employee

Hello sam,

"const char _PTR" is not selected since using CONST modifier  puts the variable into non volatile memory, which means the access would take more time, than if the variable is in RAM ( volatile memory).  This way MQX can quickly parse the structure of the task to Identified.


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

5 Replies
725 Views
matthewkendall
Contributor V

It is worth noting that your task doesn't really have a name, in the sense that there is no property of the task itself that holds the name. Rather, your task has a task id (which is unique) and a pointer to the template from which it was created. That template has a name property. So the way you lookup a name for your task at runtime is to follow the reference to the template and find the name there. Many tasks may be created from the same template, and name lookups on all of them will lead back to the same name. And if you change that template entry at runtime, all such tasks will then resolve to the new name.

725 Views
sam_
Contributor III

What about locally (automatically) created task template structures?  This would seem to imply that since the object is destroyed when the function returns, the task would not be able to resolve its name (since the task template structure is released).  Maybe I am misunderstanding this, but I had thought MQX would somehow maintain each parameter in the template structure internally to its API and I would be free to release my memory.

0 Kudos
725 Views
matthewkendall
Contributor V

In the special case of creating a task from a local template (i.e. passing a null template index to _create_task() along with a pointer to a local template), I believe _task_create() will make a copy of the passed template which is stored at the end of the created task's stack. Thus the creator can free the template after the task is created, and tasks created this way each have their own copy of a template. I don't see this behaviour documented, but it exists in _task_init_internal() in task.c (part of the PSP). And this is pretty much how it has to work, since a task can be survived by its children.

726 Views
soledad
NXP Employee
NXP Employee

Hello sam,

"const char _PTR" is not selected since using CONST modifier  puts the variable into non volatile memory, which means the access would take more time, than if the variable is in RAM ( volatile memory).  This way MQX can quickly parse the structure of the task to Identified.


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

725 Views
sam_
Contributor III

That is fascinating.  I had no idea that the read-only data section would be parsed out and placed in flash (I assume like the text section), especially since you can strip constness in C++.  That makes sense though.

0 Kudos