RT-thread版本:RT-thread system 3.1.0
开发环境:MDK5
为了编程方便,创建了sample1.c文件,然后添加到工程中
话不多说,先上代码
#include "sample1.h" #include "rtthread.h" #define stack_size 1024 //设置动态线程栈大小 #define priority 25 //设置优先级 #define tick 10 //时间片 static rt_thread_t tid1 = NULL; static void thread1_entry(void *parameter) //线程1入口函数 { rt_base_t i; rt_uint16_t count = 0; for(i = 0; i < 10; i++) { rt_kprintf("thread1, count: %d\n", count++); } } ALIGN(RT_ALIGN_SIZE); static struct rt_thread thread2; static char thread_stack[1024]; static void thread2_entry(void *parameter) //线程2入口代码 { rt_base_t i, count = 0; for(i = 0; i < 10; i++) { rt_kprintf("thread2, count: %d\n", count++); } rt_kprintf("thread2 exit!\n"); } void sample1(void *parameter) //线程创建函数 { tid1 = rt_thread_create("thread1", thread1_entry, RT_NULL, stack_size, priority, tick ); if(tid1 != NULL) rt_thread_startup(tid1); rt_thread_init(&thread2, "thread2", thread2_entry, RT_NULL, &thread_stack[0], sizeof(thread_stack), priority-1, tick); rt_thread_startup(&thread2); } MSH_CMD_EXPORT(sample1, RT-Thread first sample); //添加到msh命令列表中