[RTT例程练习] 1.5 优先级相同线程轮转调度

本文通过实例展示了在RTT操作系统中,当多个线程具有相同优先级时,如何进行时间片轮转调度。当一个线程的时间片耗尽,调度器会将执行权转交给同优先级的其他线程。
摘要由CSDN通过智能技术生成

之前说过,相同优先级的线程,在自己的时间片用光之后,会被剥夺调度器,让给同优先级的其他线程。

程序:

#include <rtthread.h>

static struct rt_thread thread1;
static struct rt_thread thread2;
static char thread1_stack[512];
static char thread2_stack[512];

//static rt_uint32_t t1_count = 0;
//static rt_uint32_t t2_count = 0;
static void thread1_entry(void* parameter)
{
    rt_uint8_t i;
    for(i = 0; i < 6; i ++)
    {
        rt_kprintf("Thread11111111111111111111111111:\n\r");
        rt_kprintf("This is \n");
        rt_kprintf("a\n");
        rt_kprintf("demo\n");
        rt_thread_delay(10);
    }
}

static void thread2_entry(void* parameter)
{
    rt_uint8_t j;
    for(j = 0; j <60; j ++)
    {
        rt_kprintf("Thread2:\n\r");
        rt_kprintf("This is \n");
        rt_kprintf("a\n");
        rt_kprintf("demo\n");
    }
}

int r
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值