📄 fifo.cpp
字号:
/*
* @author: 魏 政
* @ID: 063420
*/
#include "fifo.h"
//constructor
fifo::fifo(int seconds_per_page):simulator(seconds_per_page) {}
void fifo::simulate(string file)
{
int time = 0; //take count of time
queue<event> waiting; //define queue waiting
loadworkload(file); //read the file
int size = workload.size(); //the size of load job
double total = 0; //total time
int nextprinttime = workload.front().arrival_time();
cout << "FIFO Simulation " << endl << endl;
for(time = 0;; time++)
{
//if workload is not empty and current time equal to the job's arrival time
while(!workload.empty() && time == workload.front().arrival_time())
{
waiting.push(workload.front()); //put the job into waiting queue
cout << " Arriving: " << workload.front().getjob()
<< " at " << time << " seconds" << endl;
workload.pop(); //delete the frist job of workload
}
//wating is not empty then print the waiting job
if(!waiting.empty())
{
//if not busy then do the waiting job
if(time == nextprinttime)
{
cout<< " Servicing: " << waiting.front().getjob()
<< " at " << time << " seconds " << endl;
total += time - waiting.front().arrival_time();
nextprinttime += waiting.front().getjob().getnumpages()*seconds_per_page;
waiting.pop();
}
}
if(workload.empty() && waiting.empty()) break;
}
cout << endl;
cout << " Total jobs: "<< size << endl;
cout << " Aggregate latency: " << total << " seconds" << endl;
cout << " Mean latency: " << total/size << " seconds" << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -