I’m trying to get to grips with rtos and I can’t seem to figure out how one might go about checking whether or not a task has been deleted.
Searching around, I stumbled upon “eTaskGetState”, however that returns data which has me confused.
Here is a quick snippet demonstrating what I mean/where I am confused
if (command.equals("on"))
{
xTaskCreate(
task_Alarm_Func, /* Task function. */
"Alarm Function", /* name of task. */
STACK_SIZE, /* Stack size of task in bytes (Usually words, but esp32 changes this)*/
NULL, /* parameter of the task */
1, /* priority of the task */
&task_Alarm_Handle); /* Task handle to keep track of created task */
}
else if (command.equals("off"))
{
if (task_Alarm_Handle != NULL)
{
vTaskDelete(task_Alarm_Handle);
}
}
else if (command.equals("test"))
{
Serial.printf("\nTask State:\n%d\n", eTaskGetState(task_Alarm_Handle));
}
The numbers received when the task is running seem to make sense with my understanding of what’s happening, however, after the task has been deleted, it indicates that the deleted task is ready…
This is not what I was expecting and I’m not quite sure how I can go about checking whether or not a task is deleted.
I have also read that it is reasonable to make task handles null after deletion, however that doesn’t really work or would be very cumbersome whenever a task deleted itself I would imagine. That is why I have left it out of the snippet for testing purposes.
If its of any help, just some background information: Im currently using a TTGO T-Display (ESPRESSIF-ESP32 240MHz Xtensa® single-/dual-core 32-bit LX6) with Platform IO on VS Code and the Arduino Serial Monitor for read/writes to Serial. The FreeRTOS version is “V8.2.0”
I also have included some delay outside of the snippet (which is happening in loop, which I think runs in idle anyways) which I think means that there should be enough time for idle to run cleanup tasks