title: Round-robin scheduling algorithm
body: <p>I'm studying operating system on <a href="http://codex.cs.yale.edu/avi/os-book/OS9/" rel="nofollow">this book</a> and my prof's slides. I'm arrived at the "Process scheduling algorithms" chapter. Talking about the RoundRobin (RR) algorithm i found some inconsistencies. I understand that is a preemptive version of the FCFS algorithm with a time-slice (quatum).
  From now on, I will use the following notation:</p>
  
  <pre><code>#1 = prof's version
  #2 = book's version
  #3 = other version
  </code></pre>
  
  <p>Here's the inconsistency (suppose a quantum of 100ms):</p>
  
  <p><code>#1</code> The RR uses two queue (Q1, Q2):</p>
  
  <ul>
  <li>Q1: queue for processes that did not end their quantum;</li>
  <li><p>Q2: queue for processes that did end their quantum;</p>
  
  <ol>
  <li>The scheduler takes the process from the head of Q1; </li>
  <li>If the process ends before the quantum expires, the process release the CPU on purpose and the scheduler takes the next process from Q1</li>
  <li>If the process doesn't end before the quantum expires, is preempted and placed at the end of Q2;</li>
  <li>When a process is <em>ready</em> it's placed at the end of Q1;</li>
  <li>When Q1 is empty, Q1 and Q2 are swapped;</li>
  </ol></li>
  </ul>
  
  <p>So when a process is blocked for an I/O request (e.g. after 30ms) and its quantum is not expired yet, is placed at the end of Q1 (I guess) and when it will be scheduled again it will use the CPU for his remaining time (70ms in this case).</p>
  
  <p><code>#2</code> (The book did not talk about <em>multiple queues</em>, so I assume it will use just one queue)</p>
  
  <ol>
  <li>The scheduler takes the process from the head of the ready queue;</li>
  <li>If the process ends before the quantum expires, the process release the CPU on purpose and the scheduler takes the next process from the ready queue</li>
  <li>If the process doesn't end before the quantum expires, is preempted and placed at the end of the ready queue;</li>
  </ol>
  
  <p><code>#3</code> <a href="https://www.cs.rutgers.edu/~pxk/416/notes/07-scheduling.html" rel="nofollow">Source</a></p>
  
  <ol>
  <li>The scheduler takes the first process in the ready queue;</li>
  <li>If the process ends before the quantum expires, the process release the CPU on purpose and the scheduler takes the next process from the ready queue</li>
  <li>If the process doesn't end before the quantum expires, is preempted and placed at the end of the ready queue;</li>
  <li>If the process is blocked by a I/O request, it's placed in a <em>waiting queue</em> and when it will became <em>ready</em> will be placed again in the ready queue;</li>
  </ol>
  
  <p>To me, these are 3 different implementations of the RR scheduling algorithm. I think that the most valuable is the <code>#3</code> because the <code>#1</code> can cause a starvation (if the process is placed in Q2 and new processes keep coming in Q1, then the process will never be scheduled again) and <code>#2</code> will waste CPU time when a process is blocked for an I/O request. So, my question is: which one is <em>the right one</em>?</p>