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;
|
||||
};
|
||||
|
@ -59,7 +59,7 @@ void fifo() {
|
|||
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++;
|
||||
}
|
||||
|
@ -76,11 +76,20 @@ 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++;
|
||||
|
||||
|
@ -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