|
因为手头上一时没有可以玩RT-Thread的板子,对于RT-Thread,只能靠猜想来揣摩。下面的线程,会怎样执行呢?
static void rt_thread_entry_led1(void* parameter)
{
/* init led configuration */
rt_kprintf("led1 init\r\n");
while (1)
{
/* led on */
rt_kprintf("led1 on\r\n");
rt_thread_delay(500); /* sleep 5 second and switch to other thread */
/* led off */
rt_kprintf("led1 off\r\n");
rt_thread_delay(500);
}
}
static void rt_thread_entry_led2(void* parameter)
{
/* init led configuration */
rt_kprintf("led2 init\r\n");
while (1)
{
/* led on */
rt_kprintf("led2 on\r\n");
rt_thread_delay(500); /* sleep 5 second and switch to other thread */
/* led off */
rt_kprintf("led2 off\r\n");
rt_thread_delay(500);
}
}
static void rt_thread_entry_led3(void* parameter)
{
/* init led configuration */
rt_kprintf("led3 init\r\n");
while (1)
{
/* led on */
rt_kprintf("led3 on\r\n");
rt_thread_delay(500); /* sleep 5 second and switch to other thread */
/* led off */
rt_kprintf("led3 off\r\n");
rt_thread_delay(500);
}
}
int rt_application_init()
{
rt_thread_t thread;
/* create led1 thread */
thread = rt_thread_create("led1",
rt_thread_entry_led1, RT_NULL,
512,
20, 5);
if (thread != RT_NULL)
rt_thread_startup(thread);
thread = rt_thread_create("led2",
rt_thread_entry_led2, RT_NULL,
512,
20, 10);
if (thread != RT_NULL)
rt_thread_startup(thread);
thread = rt_thread_create("led3",
rt_thread_entry_led3, RT_NULL,
512,
21, 5);
if (thread != RT_NULL)
rt_thread_startup(thread);
return 0;
}
建立了三个任务,都是每隔5秒就输出led信息。如图:
![](http://cache.amobbs.com/bbs_upload782111/files_27/ourdev_537506.gif)
(流程图)
那么,输出结果是怎样的呢?
我猜想:
led1 init
led1 on
led2 init
led2 on
led3 init
led3 on
led1 off
led2 off
led3 off
led1 on
led2 on
led3 on
……
led1 off
led2 off
led3 off
led1 on
led2 on
led3 on
是不是这样呢? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|