Skip to content

Instantly share code, notes, and snippets.

@astro-gokart
Created April 22, 2015 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astro-gokart/4ad600d44192b0e2899a to your computer and use it in GitHub Desktop.
Save astro-gokart/4ad600d44192b0e2899a to your computer and use it in GitHub Desktop.
tatic public void RR(Processor proc) {
System.out.printf("%d processes\n",proc.ready_queue.size());
System.out.println("Using Round-Robin");
System.out.printf("Quantum %d",proc.quantum);
int rt = 0;
Job current;
current = proc.ready_queue.peekFirst();
for(int i=0;i<proc.duration;i++) { //timer
// check what processes have arrived at time
proc.checkArrival(i);
//check if processes have finished
proc.checkFinishedProcesses(i);
//select current process
current = proc.selectJobRR(i,rt);
//adjust accordingly
if(current != null) {
if (current.arrived && !current.finished)
current.elapsed--;
}
if(rt == proc.quantum) {
rt =0;
}
rt++;
}
System.out.printf("Finished at time %d\n", proc.duration);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment