If a task is terminated with returning from the task-function, how to run the task again?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
If a task is terminated with returning from the task-function, how to run the task again?
I have thought about the option to stop it with a semaphore, but it would make the things much more complicated. As far as i understand your answer, i always have to destruct a task after termination, and then construct it again if i want it to run again.
With this approach the code will have the following structure:
Task_Struct task;
Task_Handle hTask = NULL;
bool taskStopFlag = false;
void taskFxn(UArg arg0, UArg arg1) {
// do some init
while (!taskStopFlag) {
// do some work
}
// do some cleanup
}
bool startTask() {
taskStopFlag = false;
Task_Param taskParam;
Task_Params_init(&taskParams);
taskParams.stackSize =
...
Task_construct( &task, &taskFxn, &taskParam, NULL);
hTask = Task_handle(&task);
return true;
}
bool stopTask() {
taskStopFlag = false;
if (hTask ==NULL) return true; // fast return if task does not exist
int cnt = 0;
Task_Mode taskMode = Task_getMode(hTask);
while ((cnt <maxWait) && (taskMode != Task_Mode_TERMINATED)) {
Task_sleep(100000);
taskMode = Task_getMode(hTask);
}
if (taskMode == Task_Mode_TERMINATED) {
Task_destruct(&task);
hTask = NULL;
return true;
} else
return false;
}
Do you see any problems with this approach?
PS: The function to insert source code into a message does not work. i got the following error:
You don't have permission to access "">e2e.ti.com/.../configure on this server.
Reference #18.c7d6dd58.1618944356.1eb9033b