Reputation: 77
I am using multi threading to execute multiple tasks which are available in the queue one by one. After one task ends, I execute another task but while executing the second task in queue, I am facing error.
E (18470) FreeRTOS: FreeRTOS Task "taskTwo" should not return, Aborting now!
Here is my code,
QueueHandle_t priorityTwoQue;
TaskHandle_t thTwo;
void receiveTaskDataFromSomeFunction() {
dataholder = (struct DataHolder *)malloc(sizeof(struct DataHolder));
extractData(jsonBuffer, dataholder);
jsonBuffer.clear();
SerialDebug.print("Requst Sending To Que");
xQueueSend(priorityTwoQue, &dataholder, portMAX_DELAY);
processQueue();
}
void processQueue() {
delay(100);
SerialDebug.println("Creating Task Prio 2");
xTaskCreate(taskPriorityTwo, "TaskTwo", 5000, NULL, 2, &thTwo);
}
void taskPriorityTwo(void * paramter) {
SerialDebug.println("Task Initiated");
threadTask(priorityTwoQue, "task2");
vTaskDelete(thTwo);
}
void threadTask(QueueHandle_t priorityQue, String taskName) {
struct DataHolder *taskdataholder;
xQueueReceive(priorityQue, &taskdataholder, portMAX_DELAY);
SerialDebug.print("Executing Task");
executeHttpRequest(taskdataholder);
requestInProgress = false;
processQueue();
}
In the above code receiveTaskDataFromSomeFunction() is called whenever new task request is received, how ever in my case 4 requests are received one by one with an interval of 1 second. Hence i am putting them into the queue. Each request is executed as an http request which takes 5 seconds to compelete.
This code executes the first request without any issue but on executing the second request i get the error which i have mentioned above.
My question is how can i resolve this issue of executing the tasks which are available in queue one by one.
Upvotes: 0
Views: 2376
Reputation: 2247
In the RTFreeOS manual it states that tasks should run in an endless loop, so not terminate, ever. If they do terminate, they will need to be deleted with vTaskDelete(NULL);
, as mentioned by HS2.
See also this question/answer: FreeRTOS Task should not return - ESP32
Upvotes: 1
Reputation: 179
I think dynamically creating/deleting tasks for this purpose is not the best approach. Why not keeping the task running just processing incoming requests ?
However, better use vTaskDelete(NULL);
to self-delete a task.
The global task handle might get re-used/overwritten. Also it seems you don‘t really need the task handle. It‘s optional for xTaskCreate
and you can specify NULL for the handle argument if you‘re not interested in it.
And you should do some error checking ;)
Upvotes: 1