现象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++;
}
}