Normally the current active task for a CPU is determined from the head of g_assignedtasks[cpu] using the this_task() macro. g_running_tasks[cpu] is used only during interrupt handle to deal with the case where a context switch occurred and g_running_tasks[cpu] no longer refers to that task that was running when the interrupt handler was entered before the context switch.
Normally the current active task for a CPU is determined from the head of g_assignedtasks[cpu] using the this_task() macro. g_running_tasks[cpu] is used only during interrupt handle to deal with the case where a context switch occurred and g_running_tasks[cpu] no longer refers to that task that was running when the interrupt handler was entered before the context switch.
As I recall, g_running_tasks[] is only used if a crash occurs in an interrupt handler. Then the stack that you want to dump is the stack of the task that was running at the time of the interrupt, not the new task which has not even ran yet.
in nuttx code base SMP mode, a descriptions of g_running_tasks object says that:
/* g_running_tasks[] holds a references to the running task for each cpu.145 * It is valid only when up_interrupt_context() returns true.146 */147148 FAR struct tcb_s *g_running_tasks[CONFIG_SMP_NCPUS];
So, why g_running_tasks only valid in interrupt context mode? did this means we could not use the g_running_tasks to reference the current thread in thread context?
It is assigned a value only when the interrupt occurs:
sched/irq/irq_dispatch.c: g_running_tasks[this_cpu()] = this_task();
And is invalid outside of interrupt handling.
Normally the current active task for a CPU is determined from the head of g_assignedtasks[cpu] using the this_task() macro. g_running_tasks[cpu] is used only during interrupt handle to deal with the case where a context switch occurred and g_running_tasks[cpu] no longer refers to that task that was running when the interrupt handler was entered before the context switch.
So, you cannot use in g_running_tasks[cpu] thread code. Use the macro this_task() instead which will safely get the head of the g_assignedtasks[cpu] array.
NOTE: These are all internal OS interfaces and none of them
should be used applications.
Greg
Normally the current active task for a CPU is determined from the head of g_assignedtasks[cpu] using the this_task() macro. g_running_tasks[cpu] is used only during interrupt handle to deal with the case where a context switch occurred and g_running_tasks[cpu] no longer refers to that task that was running when the interrupt handler was entered before the context switch.
As I recall, g_running_tasks[] is only used if a crash occurs in an interrupt handler. Then the stack that you want to dump is the stack of the task that was running at the time of the interrupt, not the new task which has not even ran yet.