fifo rule modified
This commit is contained in:
parent
805d1bb949
commit
a6772502e8
|
@ -12,8 +12,8 @@ using namespace std;
|
|||
struct process_detail {
|
||||
//cpu_burst_times[0] is arrival time
|
||||
int pid;
|
||||
vector<int> cpu_burst_times;
|
||||
vector<int> io_burst_times;
|
||||
vector<int> burst_times;
|
||||
// vector<int> io_burst_times;
|
||||
int in_cpu;
|
||||
int ptr = 0;
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ struct process_detail {
|
|||
struct clock{
|
||||
int push_signal; //boolean
|
||||
int timer;
|
||||
|
||||
|
||||
};
|
||||
|
||||
//// operator overloading
|
||||
|
@ -43,29 +43,29 @@ struct process_detail* CPU = NULL;
|
|||
int clock = 0;
|
||||
|
||||
void fifo() {
|
||||
|
||||
|
||||
//clock initialized to 0
|
||||
struct clock time;
|
||||
memset(&time, 0, sizeof(struct clock));
|
||||
int process_count = processes.size();
|
||||
|
||||
|
||||
//ready queue initialized as process 1 will arrive at time 0
|
||||
ready_queue_fifo.push(processes[0]);
|
||||
processes[0].i++;
|
||||
|
||||
|
||||
while(true){
|
||||
|
||||
|
||||
//managing arrival times
|
||||
for(int i = 0; i < process_count; ++i) {
|
||||
//if process not in cpu
|
||||
if(proccesses[i].in_cpu != 1) {
|
||||
if(time.timer == processes[i].cpu_birst_times[0]) {
|
||||
if(time.timer == processes[i].burst_times[0]) {
|
||||
ready_queue_fifo.push(processes[ptr]);
|
||||
processes[i].i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//THE FIFO RULE
|
||||
if(CPU == NULL) {
|
||||
CPU = ready_queue_fifo.front();
|
||||
|
@ -76,16 +76,25 @@ void fifo() {
|
|||
//check cpu_burst complete
|
||||
for(int i = 0; i < process_count; ++i) {
|
||||
if(proccesses[i].in_cpu == 1) {
|
||||
if(timer.push_signal + CPU->cpu_birst_times[1] == time.timer){
|
||||
waiting.push_back(CPU);
|
||||
if(timer.push_signal + CPU->burst_times[ptr] == time.timer){
|
||||
waiting.push_back(CPU); // process added to waiting queue
|
||||
CPU->in_cpu = 0;
|
||||
CPU = ready_queue_fifo.front(); // process added to CPU
|
||||
CPU->in_cpu = 1;
|
||||
ready_queue_fifo.pop();
|
||||
timer.push_signal = timer.push_signal + CPU->burst_times[ptr] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// removing form wait
|
||||
|
||||
|
||||
}
|
||||
time.timer++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
cout << "fifo" << endl;
|
||||
return;
|
||||
}
|
||||
|
@ -117,16 +126,16 @@ int main(int argc, char **argv) {
|
|||
memset(&pd,0,sizeof(struct process_detail));
|
||||
|
||||
while(iss>>word){
|
||||
if(i == 0){
|
||||
pd.cpu_burst_times.push_back(stoi(word));
|
||||
}
|
||||
else if(i % 2 == 0){
|
||||
pd.io_burst_times.push_back(stoi(word));
|
||||
}
|
||||
else if(i % 2 == 1){
|
||||
pd.cpu_burst_times.push_back(stoi(word));
|
||||
}
|
||||
i++;
|
||||
// if(i == 0){
|
||||
// pd.cpu_burst_times.push_back(stoi(word));
|
||||
// }
|
||||
// else if(i % 2 == 0){
|
||||
// pd.io_burst_times.push_back(stoi(word));
|
||||
// }
|
||||
// else if(i % 2 == 1){
|
||||
// }
|
||||
pd.burst_times.push_back(stoi(word));
|
||||
// i++;
|
||||
// cout << stoi(word) << endl;
|
||||
}
|
||||
pd.pid = pid;
|
||||
|
|
Loading…
Reference in New Issue