1

I start a thread in zephyr like this:

K_THREAD_DEFINE(my_name, STACKSIZE, my_func, NULL, NULL,
        NULL, PRIORITY, 0, 0);

but it does crash after some time. How do I check it's status to restart it when it crashed?

f.b.
  • 490
  • 1
  • 5
  • 17
  • Perhaps better not to let it crash in the first place? In any case AFAIK threads cannot crash, only exit. If a thread crashes the whole process crashes. – john Sep 14 '22 at 08:23

1 Answers1

0

The uart shell has a command that prints all threads running. It is registered as the function cmd_kernel_threads (at zephyr\subsys\shell\modules\kernel_service.c:144 for my version). Starting from there you should find your info.

static int cmd_kernel_threads(const struct shell *shell,
                  size_t argc, char **argv)
{
    ARG_UNUSED(argc);
    ARG_UNUSED(argv);

    shell_print(shell, "Scheduler: %u since last call", sys_clock_elapsed());
    shell_print(shell, "Threads:");
    k_thread_foreach(shell_tdata_dump, (void *)shell);
    return 0;
}

I could be wrong but I believe you wont be able to access the thread chained list (_kernel.threads in thread.c). There should be a better way but you can write a callback to give to k_thread_foreach instead of shell_tdata_dump. In this callback you'd look sequentially for a thread named as yours.

Zoyolin
  • 25
  • 5