Skip to content
Snippets Groups Projects
Commit 38001d74 authored by sfphoton's avatar sfphoton
Browse files

Bugfix: Main class could only detect one task arriving in the same CPU cycle

parent fb54f0f6
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ public class Global { ...@@ -7,7 +7,7 @@ public class Global {
private SRTF srtf = new SRTF(this); //high priority scheduler private SRTF srtf = new SRTF(this); //high priority scheduler
private RR rr = new RR(this); //low priority scheduler private RR rr = new RR(this); //low priority scheduler
String history = ""; //a string with tha names of task that have taken control so far - I will use this only for the output String history = ""; //a string with the names of task that have taken control so far - I will use this only for the output
public void add(Task t) { public void add(Task t) {
Main.schedulersEmpty=false; Main.schedulersEmpty=false;
......
...@@ -48,12 +48,14 @@ public class Main { ...@@ -48,12 +48,14 @@ public class Main {
if(tasks.size()==0) {System.out.println("\n\n"); return;} if(tasks.size()==0) {System.out.println("\n\n"); return;}
for(int now = 0; tasks.size()>0 || !schedulersEmpty; now++) { for(int now = 0; tasks.size()>0 || !schedulersEmpty; now++) {
//adding incoming tasks //adding incoming tasks
for(int i=0; i<tasks.size(); i++) { for(int i=0; i<tasks.size(); i++) {
if(tasks.get(i).startTime == now) { if(tasks.get(i).startTime == now) {
scheduler.add(tasks.get(i)); scheduler.add(tasks.get(i));
runningTasks.add(tasks.get(i)); runningTasks.add(tasks.get(i));
tasks.remove(i); tasks.remove(i);
i--; //we just removed an item so the i-th is the next one
} }
} }
......
...@@ -57,6 +57,6 @@ public class SRTF { ...@@ -57,6 +57,6 @@ public class SRTF {
} }
public boolean isEmpty() { public boolean isEmpty() {
return activeTask==null && waitingQueue.size()==0; return (activeTask==null && waitingQueue.size()==0);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment