void System::nextEvent(){ auto event = eq.top(); currTime = event->time; eq.pop(); if( event != NULL ){ auto t = event->type; if(t == START ){ auto e = std::dynamic_pointer_cast<StartTask> (event); e->nextProcess(); } else if(t == CPU ){ auto e = std::dynamic_pointer_cast<CPUDone> (event); e->nextProcess(); } else if(t == IO ){ auto e = std::dynamic_pointer_cast<IODone> (event ); e->nextProcess(); } else if(t == END){ endTime = currTime; std::dynamic_pointer_cast<EndSim> (event )->nextProcess(); return; } } else{ assert(true); } }
// // main - The simulator's main routine // int main(int argc, char **argv){ int processes[10]; init(); int i; for(i=0;i<10;i++){ processes[i]=100; printf("Scheduled Process: %d\n", i); addProcess(i); } int process = 0; while(hasProcess()){ process = nextProcess(); for(;;){ printf("Process %d executed\n", process); processes[process]--; if(processes[process]<0){ printf("Process %d Finished\n", process); break; } } } exit(0); //control never reaches here }
// // main - The simulator's main routine // int main(int argc, char **argv){ int processes[14]; init(); int i; for(i=0;i<10;i++){ processes[i]=100; int priority = i%4; printf("Scheduled Process: %d, Priority:%d\n", i, priority); PCB* proc = (PCB *) malloc(sizeof(PCB)); proc->pid = i; proc->priority=priority; addProcess(proc); } PCB* process = NULL; int count = 0; int time = 0; while(hasProcess()){ process = nextProcess(&time); if(!process){ printf("NULL Process, something went wrong in your code.\n"); exit(1); } for(;time>0;time--){ printf("Process %d executed\n", process->pid); processes[process->pid]--; if(processes[process->pid]<0){ printf("Process %d Finished\n", process->pid); } count++; } if(processes[process->pid]>=0){ addProcess(process); } if(count==400){ for(;i<14;i++){ processes[i]=100; int priority = i%4; printf("Scheduled Process: %d, Priority:%d\n", i, priority); PCB* proc = (PCB *) malloc(sizeof(PCB)); proc->pid = i; proc->priority=priority; addProcess(proc); } } } exit(0); //control never reaches here }