0
votes

I am confused with a basic concept of Round Robin CPU process scheduling, where the short term scheduler adds the process to the ready queue.

If there are 3 process P0, P1 and P2 in the system and a context switch occurs for P1 at 5 seconds and at the same time P2 ARRIVES (i.e. at 5th second). In such a case which process will be inserted first in the ready queue, P1 or P2? The overall average waiting time may not differ in both the cases but the individual waiting time of a process will differ.

2
Whoever obtains the lock first?M. Shaw
@M.ShawCan you elaborateuser3256888
In computing in general, nothing happens at the same time. It might be really close, but something always happens before the other thing.James Z
@JamesZ True, but things can happen at the same time on a multicore system. I addressed synchronization in my answer.Jack Humphries

2 Answers

0
votes

It's not possible for both P1 and P2 to be added to the ready queue at the same time. There must be some order in which they are added (either P1 is added before P2, or P2 is added before P1), since when you want to add a process to the ready queue, you must synchronize accesses to the ready queue in order to avoid corrupting the queue. On a single core system, you might do this by disabling interrupts while you are modifying the queue. On a multicore system, you might do this through some combination of locks and disabling interrupts, depending on the implementation of the kernel.

As an example on a single core, let's say a timer interrupt arrives that causes you to preempt P1. You disable interrupts when the timer interrupt is received. While you are adding P1 to the queue, it is not possible for P2 to become available, whether this is due to some I/O completing for P2, or the user starting up P2, etc. Interrupts have been disabled, so your kernel won't be bothered with any events regarding P2 until it has added P1 to the queue and enabled interrupts. The same is true for P2 - if you are adding P2 to the queue and a timer interrupt arrives that should cause P1 to be preempted, the timer interrupt will just be ignored until P2 has been added to the queue.

0
votes

P1 will be given fist chance of execution because of its aging. While P2 will be added at the end of queue just before the last executed process.

This means that P1 will start executing and P2 will be added at end of queue, just before last executed proces i.e. P0. Thus your ready queue will be like P1, P2, P0 where P1 is currently executing.