提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
提示:这里可以添加本文要记录的大概内容:
提示:以下是本篇文章正文内容,下面案例可供参考
一、 实验目的
LLF 算法:该算法是根据任务紧急(或松弛)的程度,来确定任务的优
先级。任务的紧急程度愈高,为该任务所赋予的优先级就愈高,以使
之优先执行。例如,一个任务在 200ms 时必须完成,而它本身所需的
运行时间就有 100ms,因此,调度程序必须在 100ms 之前调度执行,
该任务的紧急程度(松弛程度)为 100ms。又如,另一任务在 400ms 时
必须完成,它本身需要运行 150ms,则其松弛程度为 250ms。在实现
该算法时要求系统中有一个按松弛度排序的实时任务就绪队列,松弛
度最低的任务排在队列最前面,调度程度总是选择就绪队列中的队首
任务执行。
二、 实验原理
!
完成时间 = 开始时间 + 需要运行时间周转时间 = 完成时间 - 到达时间
平均周转时间 = (完成时间 - 到达时间)/进程数
平均带权周转时间 = (周转时间 / 需要运行时间)/进程数
include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <random>
#include <ctime>
#include <functional>
#include <algorithm>
#include <queue>
using namespace std;
static int MAXCUM = 5;//RR算法-定义进程最多为5个
static int currentTime = 0;//初始化当前时间为0
#define E 0//表示进程处于End状态
#define W 1//表示进程处于wait状态
static int NameSeed[20] {
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
static int flagA = 0;//进程名字标记
static int flagB = 0;
static int timeSlice = 0;//初始化时间片值为0
class process
{
public:
process(string processName, int runTime, int status)
{
this->m_ProcessName = processName;
this->m_RunTime = runTime;
this->m_Status = status;
}
string m_ProcessName;
int m_MinimumTolerance;//最小容忍度
int m_NeedRunTime;//还需要的运行时间
int m_HaveRunTime;//已经运行的时间
int m_RunTime;//运行时间
int m_Looseness;//松弛度
int m_Status;//W和E的状态标记
int m_Deadline;//截止时间
int m_ArriveTime;
int m_FinishTime;
int m_TurnaroundTime;//周转时间
double m_AuthorityTurnaroundTime;//带权周转时间
bool operator<( const process &p)const
{
return m_ArriveTime<p.m_ArriveTime;
}
};
int calcuLoose(process p, int currentTime)