Pergunta

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)

Foi útil?

Solução

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.

Outras dicas

a) The CPU fills a buffer in the sound card, which plays from the buffer while the CPU is doing other stuff. So the CPU doesn't have to care about the sound card all the time.

b) Switching between processes takes place in the milli- or even microsecond time range, so you just won't notice that as a human.

c) Processes that have nothing to do (like wordpad waiting for a key) tell the OS they're idle, so the OS doesn't give them any time until something happens (a key is pressed, or windows have been moved so they have to be redrawn).

d) CPUs are fast. Even if you could type 10 keys per second, the CPU won't take more than 100 microseconds per key (actually much less but this value makes it easier to calculate), so while typing at 10 key/s, you're giving work for 1ms/s to the CPU. So you'll take 0.1% of your CPU time while typing. You won't even see CPU usage in the taskmanager go up.

Cycles into processor are not round robin, because round robin means equality on the shares, and is not. You can change all the cycles assignament percents using priority(windows) or using nice (Linux). CPU is dinamically assigned, between cycles.

In your context, putting more priority to the sound you will get lag on the keystroke repeating speed. (just like when you do into a 133Mhz computer)

A lot of extra info: Is a usual problem to say CPU is the unique that makes the pc powerfull. But really not. IS the core, but not the engine.

Your sound is NOT proccessed by main proccesor as we could "think". Audio chips are for. They got the concrete sound chip processing load. So, if you push play... the CPU push the play, draws a player, put info (mp3 mb files) into ram, then sends to the soundchip, and the Sound chip does the hard work.

Anyway, the computer workflow is not CPU->keyboard->CPU nor like that. You have to check RAM, where the sound is stored, and passed to the sound chip. The latency, current state, current load...

Motherboard is the road betteen components (micro, cpu, sound, vga, other), so the sum of total BUS MHz (cycles) it quite more important thant your CPU power.

As a final note. If you got problems when using sound with another apps/process, simply add more priority to the process.

The "background state" of the sound player maybe is one reason to get less priority by itself...but im not sure.

I know that is not a cool asnwer. Maybe re-edit them. Just put the ideas on the table.

I suggest you to try at least 3 sound players with the same file. If nothing has changed, try the same with 3 txt editors. If nothing has changed, we are into a space-tem hole.

I think is the RAM, and if not, the motherboard. Because you dont post any ANY data about your system, i cannot say nothing more. If you have 4gb ram, IS NOT. If you have 133Mhz CPU, we need to talk about it :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top