How do I get all task handles without calling uxTaskGetSystemState?

I understand that I can use uxTaskGetSystemState to retrieve all task handles. However, isn’t there a more low-level way of getting pointers to all tasks? I mean, the RTOS itself must already have an array or a linked list with pointers to all tasks handles? What is the variable name of that array or beginning node of that linked list?

FreeRTOS maintains multiple lists according to the task state. You will need to traverse all those lists which is what uxTaskGetSystemState essentially does.

Here are all the task lists - FreeRTOS-Kernel/tasks.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub

I see. But the struct tskTaskControlBlock objects are always at fixed addresses (as long as the corresponding task isn’t deleted), correct? So if I don’t create or delete tasks during runtime, it’s enough that I call uxTaskGetSystemState once, after all tasks have been created in the beginning of the code?

Correct.

That is true in your case as you only need the xHandle member of TaskStatus_t. Other members such as task state, stack information etc. keeps changing throughout the lifetime of the task.

1 Like