白日梦c先森 2021-08-27 16:30
浏览 119
已结题

刚入RT-Thread遇到的问题,相同优先级的两个线程不能轮流执行

现象1:有优先级相同的两个线程A和B,线程都是死循环,当先运行的线程A,且没有让出cpu的动作,这种情况下的现象是线程A一只在执行,B没有执行。
疑问1:居然是两个相同优先级的线程 ,且没有比他们再高的,那么执行A的时候,时间片到了,为什么不会去执行B?

现象2:当先运行的A中有rt_thread_mdelay()的情况下,那么A和B就会轮流执行
疑问2:A有rt_thread_mdelay()可以让出cpu这个理解,当执行到B的死循环之后,怎么又可以回到A?这是时间片到了?为什么现象1不出现?

void led_thread_entry(void *parameter);
void timer_thread_entry(void *parameter);
static rt_thread_t led_thread;
static rt_thread_t timer_thread;

void Task_Init(void)
{
    led_thread = rt_thread_create("ledThread",
                             led_thread_entry,
                             RT_NULL,
                             256,
                             2,
                             10);

    if(led_thread != RT_NULL)
    {
        rt_thread_startup(led_thread);
    }        
    
    timer_thread = rt_thread_create("timerThread",
                             timer_thread_entry,
                             RT_NULL,
                             256,
                             2,
                             10);
        
    if(led_thread != RT_NULL)
    {
        rt_thread_startup(timer_thread);
    }
                                                         
}

void led_thread_entry(void *parameter)
{
    rt_uint32_t count = 0;
    
    while (1)
    {
        if(0 == (count % 100))
        {
            rt_kprintf("led_thread  count = %d\n", count);
//            rt_thread_mdelay(1);
        }
        count++;
     }    
}

void timer_thread_entry(void *parameter)
{
    
    rt_uint32_t count = 0;
    
    while (1)
    {
        if(0 == (count % 100))
        {
            rt_kprintf("timer_thread count = %d\n", count);
            rt_thread_mdelay(1);
        }
        count++;
     }
}


  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 9月4日
    • 创建了问题 8月27日

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog