|
![](/i/fill.gif) |
Jim Henderson <nos### [at] nospam com> wrote:
> If that program takes 100% of the CPU, then *nothing* else gets any CPU -
> other applications, the OS, etc. Those things need resources, too.
That's not how pre-emptive multitasking works.
You don't need "free CPU time" for task switching to work. It's not like
a program using 100% of CPU time would mean the OS has lost control.
100% CPU time simply means that the OS is giving all the CPU time to
that process because nothing else needs the CPU. There's no need to keep
the CPU idle for no reason if only one process requests CPU time.
CPUs support this thing called a clock interrupt. This means that at
certain intervals (the interval can be set up by the OS) a clock circuit
sends a signal to the CPU, which causes the CPU to stop whatever it was
doing and jump to a predefined location (which also can be set up by
the OS). This predefined location is usually the task manager of the OS.
The task manager has a list of processes, categorized by their priority,
whether they are idle or not (there exist OS system calls which a process
can call to make itself idle) and other details.
If only one process is non-idle, the task manager simply resumes the
execution of that process. The effective result of this is that that process
gets 100% of CPU time (well, more precisely something like 99.9999% because
the task manager takes that 0.0001% to check the list of processes).
It's impossible for a process to block a pre-emptive OS completely.
When the clock signal interrupts the CPU, the CPU just stops executing
that process, period. There's no way around it. When that happens, the
OS is free to do whatever it wants. If another process has just started,
the OS can share CPU time with it, no problem. If they have equal priorities
and both are CPU-intensive, they will get 50% each.
Some people really do seem to have some kind of confusion with this.
They believe that taking 100% of CPU time means that no CPU time is left
for the OS to perform task switching. This is just not how CPUs and
pre-emptive multitasking works. The OS is not hindered in any way.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |