RT-Thread Getting Started Study Notes-Create a thread que não pode ser excluído

Prefácio

  • Depois de aprender os componentes do kernel RT-Thread e o gerenciamento de thread, de repente descobri que quando um thread é criado, o nome pode usar RT_NULL.
  • Crie um tópico sem nome, funciona bem, mas não pode ser excluído

 

Código relacionado

#include <rtthread.h>

#define DBG_SECTION_NAME    "noname"
#define DBG_LEVEL           DBG_LOG
#include <rtdbg.h>

 /* led test */
extern void led_red_on(void);
extern void led_red_off(void);
extern void led_grn_on(void);
extern void led_grn_off(void);
extern void led_blu_on(void);
extern void led_blu_off(void);

/* no name thread1 */
static void no_name_task1(void* param)
{
    LOG_D("no name thread1 start!\n");

    while (1)
    {
        led_red_on();
        rt_thread_mdelay(2000);
        led_red_off();
        rt_thread_mdelay(2000);
    }
}

/* no name thread2 */
static void no_name_task2(void* param)
{
    LOG_D("no name thread2 start!\n");

    while (1)
    {
        led_blu_on();
        rt_thread_mdelay(3000);
        led_blu_off();
        rt_thread_mdelay(3000);
    }
}

/* no name thread3 */
static void no_name_task3(void* param)
{
    LOG_D("no name thread3 start!\n");

    while (1)
    {
        led_grn_on();
        rt_thread_mdelay(4000);
        led_grn_off();
        rt_thread_mdelay(4000);
    }
}

void no_name_init(void)
{
    rt_thread_t tid;

    tid = rt_thread_create(RT_NULL, no_name_task1, RT_NULL, 2048, 28, 50);
    rt_thread_startup(tid);

    tid = rt_thread_create(RT_NULL, no_name_task2, RT_NULL, 2048, 28, 50);
    rt_thread_startup(tid);

    tid = rt_thread_create(RT_NULL, no_name_task3, RT_NULL, 2048, 28, 50);
    rt_thread_startup(tid);
}

void no_name_del(void)
{
    rt_thread_t tid;

    tid = rt_thread_find(RT_NULL);
    if (tid != RT_NULL)
    {
        rt_thread_delete (tid);
    }
    else
    {
        LOG_D("Not find thread!");
    }
}

MSH_CMD_EXPORT(no_name_init, no_name_init);
MSH_CMD_EXPORT(no_name_del, no_name_del);
msh >no_name_init
msh >[D/noname] no name thread1 start!

[D/noname] no name thread2 start!

[D/noname] no name thread3 start!


msh >list_thread
thread   pri  status      sp     stack size max used left tick  error
-------- ---  ------- ---------- ----------  ------  ---------- ---                                                                                      
         28  suspend 0x0000007c 0x00000800    07%   0x0000002e 000                                                                                        
         28  suspend 0x0000007c 0x00000800    07%   0x0000002e 000                                                                                         
         28  suspend 0x0000007c 0x00000800    07%   0x0000002e 000
pms       28  suspend 0x0000009c 0x00000800    07%   0x0000002f 000
tshell    20  running 0x00000084 0x00001000    12%   0x00000005 000
serial    25  suspend 0x00000088 0x00000400    13%   0x0000000a 000
tidle0    31  ready   0x00000080 0x00000800    06%   0x00000016 000
timer      4  suspend 0x00000060 0x00000200    18%   0x00000009 000
msh >

msh >no_name_del
[D/noname] Not find thread!

 

Interpretação

  • Ele pode criar um thread sem nome, porque quando o objeto kernel é inicializado, o comprimento do nome não é julgado
  • É impossível excluir um thread sem um nome porque o objeto kernel é pesquisado por nome.

 

Resumindo

  • Precisa continuar a estudar o código do kernel RT-Thread, código de gerenciamento de thread e usar RT-Thread corretamente
  • Aprofundar o acúmulo de conhecimentos teóricos básicos.

Acho que você gosta

Origin blog.csdn.net/tcjy1000/article/details/114705710
Recomendado
Clasificación