当前位置:网站首页>High response ratio first
High response ratio first
2022-07-28 07:19:00 【▀】
High response priority scheduling algorithm (Highest Response Ratio Next) Is a kind of right CPU An algorithm for allocation of central controller response ratio .HRRN Is between FCFS( First come first serve algorithm ) And SJF( Short job first algorithm ) The compromise algorithm , Consider both job waiting time and job running time , Not only take care of short assignments, but also do not make long waiting time for long assignments , Improved scheduling performance .
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<queue>
#include<list>
#include<thread>
#include<mutex>
#include<Windows.h>
using namespace std;
#define MAX_TIME 99999
int g_time = 0;
mutex g_mutex_time;
struct process_node
{
int prcess_id; // Process number
int _start; // Entry time
void(*main_doing)(int args, char *ptr_argv[]);// Tasks completed by this process
int begin; // Starting time
int finish; // Completion time
int _function; // Run time required
int function; // Time that has been running
int wait;
bool complete; // Whether it is completed or not true complete
};
list<process_node*>q_list;// Process queue
void showlist()
{
for (auto ib = q_list.begin(); ib != q_list.end(); ib++)
{
cout << (*ib)->prcess_id << " "<<(*ib)->wait<<" ||";
}
cout << "\n";
}
void main_doing(int args, char *ptr_argv[])
{
cout << args << " This is a running instance " << endl;
Sleep(200);
}
void Come_Init_Prcess(void(*main_doing)(int args, char *ptr_argv[]), int _function) // The simulation process arrives and initializes
{
static int id = 0;
process_node *p = new process_node;
p->prcess_id = ++id;
p->_start = g_time;
p->main_doing = main_doing;
p->_function = _function;
p->begin = MAX_TIME;
p->wait = 0;
p->finish = MAX_TIME;
p->function = 0;
p->complete = false;
q_list.push_back(p);
}
void Time_End_Work(process_node & current_process)// Work before the end of the time slice
{
if (current_process.function >= current_process._function)// Judge whether it is finished
{
current_process.complete = true;
current_process.finish = g_time;
cout << " process " << current_process.prcess_id << " To complete the task " << endl;
int wait = current_process.finish - current_process.begin;
q_list.remove(¤t_process);
for (auto ib = q_list.begin(); ib != q_list.end(); ib++)
{
(*ib)->wait += wait;
}
}
}
void One_End_Process(process_node & current_process)
{
int current_point = g_time;
cout << " current time " << current_point << endl;
while (current_point + current_process._function >= g_time)
{
current_process.main_doing(current_process.prcess_id, NULL);
}
current_process.function += g_time - current_point;
Time_End_Work(current_process);
}
process_node& Obtain_Obtain()// Get priority
{
float temp = 0.0;
process_node *p_temp = nullptr;
while (q_list.size() == 0);
for (auto ib = q_list.begin(); ib != q_list.end(); ib++)
{
if ((float)(((*ib)->_function + (*ib)->wait)/ (*ib)->_function) > temp)
{
temp = (float)(((*ib)->_function + (*ib)->wait) / (*ib)->_function);
p_temp = (*ib);
}
}
cout << " The priority is the program " << p_temp->prcess_id << endl;
p_temp->begin = g_time;
return *p_temp;
}
void Run_begin()
{
while (1)
{
process_node &p_temp = Obtain_Obtain();
showlist();
One_End_Process(p_temp);
}
}
// Time instances arrive
void pthread_model()
{
time_t ts;
srand((unsigned int)time(&ts));
while (1)
{
int x_temp = 0;
lock_guard<mutex>ldg(g_mutex_time);
cout << " Time :[" << g_time << "]" << endl;
if (g_time % 2 == 0)
{
while (1)
{
x_temp = rand() % 5;
if (x_temp > 0)
{
break;
}
}
Come_Init_Prcess(main_doing, x_temp);
cout << " Instance arrives " << endl;
}
Sleep(1000);
g_time++;
}
}
int main()
{
thread th_model(pthread_model);
thread th_main(Run_begin);
th_model.join();
th_main.join();
cin.get();
}
边栏推荐
- MySQL排除节假日,计算日期差
- Current limiting ratelimiter of guava
- Install pycharm
- kali下安装nessus
- Standard C language learning summary 5
- Easypoi export interlaced style settings
- guava之EventBus
- Sysevr environment configuration: joern-0.3.1, neo4j-2.1.5, py2neo2.0
- OJ questions about fast and slow pointers in linked lists
- MySQL查询父节点下面的所有子孙节点,查询用户列表时多级(公司)部门处理,根据反射,递归树形结构工具类
猜你喜欢

win下安装nessus

Circular linked list problem

Generate create table creation SQL statement according to excel

Learning to estimate 3D hand pose from single RGB image & amp notes

Leetcode then a deep copy of the linked list

最短寻道时间优先(SSTF)

Softmax multi classification gradient derivation

Tailing microelectronics B91 general development board integrated into the trunk of openharmony community

Current limiting ratelimiter of guava

Install Nessus under win
随机推荐
Image segmentation method
Pytorch installation - CPU version
Standard C language learning summary 7
Softmax multi classification gradient derivation
Standard C language learning summary 9
深入剖析单例模式的实现
MySQL排除节假日,计算日期差
Media set up live broadcast server
guava之Retryer
Current limiting ratelimiter of guava
浅谈深分页问题
js二级联动院系
freemarker合并单元格,if、else标签的使用,null、空字符串处理
Rsync+inotify to realize remote real-time synchronization
232 (female) to 422 (male)
Standard C language learning summary 5
WiFi one click connection configuration of raspberry pie
主动扫描技术nmap详解
Addition, deletion, check and modification of sequence table
The.Joernindex database has no content after Joern runs