Search code examples
operating-systemmultiprocessingcpu-usageround-robin

Distribution of CPU cycles when multiple process are running in parallel?


My question is Are cpu cycles are given to different processess in round robin fashion ?

Conext of question is :-

i have windows system and lets say i have opened these 10 diferent processes for example playing music in media player, typing in wordpad, typing in notepad, surfing in browser etc.

As music is played in background without interruption when at the same time i am typing in wordpad . I am wondering how come music player is given continous CPU cycles. My understanding is OS is rotating the cpu cycles among different processes in round robin fashion but this switching is too fast that end user is not able to spot the interruption in music(though actually it is interrupted)


Solution

  • The simple round-robin is a way to share the computing resource among a set of processes(threads) but not the one used in Windows. Each thread has it's static and dynamic priority. The scheduler picks up the a thread with a highest priority to run and gives it a time slot to execute. If the thread consumed the time slot completely, then it is swapped out from execution by the scheduler preventively, or the thread may give the rest of the time slot back to the system voluntary if it has nothing to do more (for example it is waiting for the end of IO operation).

    In your your particular question there is another thing that creates the continuous play of sound. It is buffering. The media player reads data in advance from the media and then queues it to the hardware to play. So the hardware should always have a buffered data in advance, otherwise the sound will have interruptions. Nowadays our computers are powerful enough to supply the necessary stream to the hardware even under notable loads.

    In old days if you run many apps at once and the system starts to swap in and out the processes from the disk (from the OS point of view is more important thing than to give the media player the opportunity to run) then you could have your music played with gaps of silence.