sylixos RMS调度

RMS(Rate Monotonic Secheduling)是一种可以提供固定任务周期的调度系统。与普通的随机式的、不可预测的调度系统不同,RMS可以提供固定的、可设置的调度周期,且精度可达到纳秒级。多个RMS调度之间优先级按照周期越小优先级越高的原则。

函数原型:

      sched_rms_init()为线程 thread 创建一个rms调度器,sched_rms_destroy()用于删除一个rms调度器。sched_rms_period()启动rms调度器,period为周期。执行sched_rms_period()后会开始计时,直到下次执行sched_rms_period()时,若未到设置周期则阻塞到时间到达,若超过设置周期则会发生溢出错误;

测试代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched_rms.h>
#include <pthread.h>

int main (int argc, char **argv)
{

    int i;
    sched_rms_t rms;
    struct timespec period;
    period.tv_sec = 3;
    period.tv_nsec = 0;

    if (sched_rms_init(&rms, pthread_self()) < 0) {
        perror("sched_rms_init");
        return (PX_ERROR);
    }

    for (i = 0; i < 5; i++) {
        if (sched_rms_period(&rms, &period) < 0) {
            perror("sched_rms_period");
            
            return (PX_ERROR);
        }

        system("date");

    }

    if (sched_rms_destroy(&rms) < 0) {
        perror("sched_rms_destroy");

        return (PX_ERROR);
    }

    return (0);

}

运行结果:

若在system("data");之后加入一句sleep(5),则会迫使调度器超时,从而引发溢出超时错误,如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值