Skip to content

Fix: Round Robin scheduling processes before their arrival time (#4) - #5

Open
Abhirai2006 wants to merge 1 commit into
aadhil2k4:mainfrom
Abhirai2006:fix-round-robin-arrival-time
Open

Fix: Round Robin scheduling processes before their arrival time (#4)#5
Abhirai2006 wants to merge 1 commit into
aadhil2k4:mainfrom
Abhirai2006:fix-round-robin-arrival-time

Conversation

@Abhirai2006

Copy link
Copy Markdown

Fixes #4

Bug

The Round Robin scheduler looped through every process every round and ran whichever one still had burst time left, without ever checking whether that process had actually arrived yet. This let later-arriving processes get scheduled before their arrival time - exactly what was reported in #4.

Repro (before fix):

P4 was scheduled to run from t=5 to t=7 — two seconds before it arrives at t=7.

Root cause

while (remainingBurstTimes.some((bt) => bt > 0)) {
  for (let i = 0; i < sortedRows.length; i++) {
    if (remainingBurstTimes[i] > 0) { /* execute */ }
  }
}

There was no ready queue and no arrival-time check — it just cycled through the full process list on every pass.

Fix

Replaced this with a proper ready-queue based Round Robin:

  • A process index only enters the queue once its arrival time has passed.
  • Processes that arrive mid-quantum are enqueued before the process that just ran gets re-queued (standard RR tie-break).
  • If the queue empties out but processes are still left to arrive, the clock jumps forward to the next arrival instead of scheduling early or leaving a broken gap.

Testing

  • Verified the repro case above: P4 now correctly starts at t=8, not t=5.
  • Checked an idle-gap case (all early processes finish before the next one arrives) and a simultaneous-arrival case — both produce correct standard RR ordering.
  • Ran npm run build — compiles clean for this file (pre-existing lint warnings in SJFPriority.js/Sjf.js are unrelated to this change).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Wrong Answer in Round Robin Algorithm

1 participant