MQX 3.7 Proper Task Create-Destroy Method

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

MQX 3.7 Proper Task Create-Destroy Method

Jump to solution
1,336 Views
Tim562
Senior Contributor I

Hi All,

 

    I'm pretty new to MQX and would like to confirm that I have the right idea when it comes to dynamically creating and destroying tasks to perform transitory jobs that might be blocking in nature (or require a lot of time to complete).

 

Question 1: Is it proper to call _task_destroy() from within the child Task function I want to destroy (as in code example below) or do I need to do this from the parent function that created the task?

 

Question 2: If allowed to call _task_destroy() from within the child task I want to terminate, which is the better/proper way to do it: _task_destroy(_task_get_id()); or _task_destroy(MQX_NULL_TASK_ID); ?

 

This simplified example code seems to work as I intend I would just like to confirm that I'm doing things the "MQX" way, Thanks!

 

TASK_TEMPLATE_STRUCT MQX_template_list[] ={/*Task number, EntryPoint, Stack, Pri, String, Auto?                */  {MAIN_TASK,  MAIN_task,  5000,  9,   "main",  MQX_AUTO_START_TASK},  {TEMP_TASK,  My_Task,    5000,  9,   "mtask", 0},  {0,          0,          0,     0,    0,      0}};void MAIN_task(uint_32 initial_data)   {   boolean bNeedTask = 0;   _task_id tiNewTaskID;   if(bNeed_Task == 1)      {      tiNewTaskID = _task_create(0, TEMP_TASK, 0);      if(tiNewTaskID == MQX_NULL_TASK_ID)         {         //Log Error...         }      bNeed_Task = 0;      }// Do Stuff Here....   }void my_task(uint_32 initial_data)   {   //Do something here....   _task_destroy( _task_get_id() ); //Which way is better/proper??// _task_destroy(MQX_NULL_TASK_ID); //   return;   }

 

0 Kudos
1 Solution
385 Views
c0170
Senior Contributor III

Hi Tim562,

 

Answers to your questions,

1. It is proper to call call_task_destroy or simple return from the function and it will be destroyed.

2. _task_destroy(MQX_NULL_TASK_ID)

 

 

Regards,

MartinK

View solution in original post

0 Kudos
2 Replies
386 Views
c0170
Senior Contributor III

Hi Tim562,

 

Answers to your questions,

1. It is proper to call call_task_destroy or simple return from the function and it will be destroyed.

2. _task_destroy(MQX_NULL_TASK_ID)

 

 

Regards,

MartinK

0 Kudos
385 Views
Tim562
Senior Contributor I

Thank you Kojto, I appreciate your reply.

 

~Tim

0 Kudos