AnsweredAssumed Answered

MQX 3.7 Proper Task Create-Destroy Method

Question asked by Tim Hutchinson on Jan 12, 2012
Latest reply on Jan 13, 2012 by Tim Hutchinson

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;   }

 

Outcomes