嵌入式技术william hill官网
直播中

王刚

7年用户 1279经验值
私信 关注
[问答]

在线程里调用rt_thread_self()打印线程名打印为空?

使用RT-Thread的过程中发现常常进assert,发现是在某个线程调用mutex时挂死的,所以想在rt_thread_self里检测是从哪个线程进来的。
但打印出来有的时候是空值,why?
除了可以通过看thread->name,还有办法可以达到看当前是在哪个线程的目的吗?
void rt_assert_handler(const char *ex_string, const char *func,
                       rt_size_t line) {
  volatile char dummy = 0;
  if (rt_assert_hook == RT_NULL) {
#ifdef RT_USING_MODULE
    if (dlmodule_self()) {
      /* close assertion module */
      dlmodule_exit(-1);
    } else
#endif /*RT_USING_MODULE*/
    {
      rt_thread_t cur_thread = rt_thread_self();
      rt_kprintf("assertion thread: %s\n", cur_thread->name);
      //   rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n",
      //              ex_string, func, line);
      while (dummy == 0)
        ;
    }
  } else {
    rt_assert_hook(ex_string, func, line);
  }
}
打印输出:
2.jpg


回帖(1)

杨帆

2023-4-17 14:36:35
你可以试试把当前线程都打出来,类似命令ps一下。看看哪个线程当前在跑。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分