From: jarman@ee.ualberta.ca (Andrew Jarman)
Subject: Re: preemptive multi-tasking
Organization: University Of Alberta, Edmonton Canada
Date: Wed, 15 Apr 1992 04:24:17 GMT

crum@edwards-vax.af.mil writes:


>  Now I'm confused about this preemptive multi-tasking thing.  Are you saying
>that if I have 4 DOS applications open in MS Windows and 3 are idle in the
>background, that only the forground application will get CPU cycles, and the 3
>in the background will get none as long as they are idle?

>  If one of the background DOS applications is a communications program which
>is not receiving anything, then a download begins, will it take CPU cycles 
>from the forground application as needed to prevent loss of data?

>Please explain.
If these were OS/2 shells, then exactly what you have described would happen.
An OS/2 program asks for input, and when it starts waiting for it, the
kernel suspends the program (ie. no CPU time) until input is ready.  Thus,
wordprocessors, comm programs, etc. take very little background time.  In
the case for a communications program, and data coming in from the comm
port will 'wake' up the program, allowing it to process until it ran
out of data, whereby it 'sleeps' again.  Of course, as it runs, the system
can take the CPU away if higher priority programs become ready to run.

Now DOS programs under OS/2 are a little different.  Since they have no
'real' way of telling OS/2 they are waiting for characters, they are not
so efficient.  DOS programs typically poll the input devices, and if nothing
is ready, they just keep polling.  OS/2 tries to detect this polling, and
if it finds it, it switches the CPU to another program.  The system can
never be completely sure the program will keep polling, so a little CPU time
must be given to the program.  Of course, these DOS programs are also
pre-empted when a higher priority program becomes ready to run (ie. its 
input has arrived).

Now, this may be interesting, but you asked about windows.  Windows has
a similar problem that OS/2 has when trying to detect polling DOS programs.
Thus, background DOS shells will also steal some CPU time.  Windows
programs, on the other hand, do not get any time unless a 'message' is
sent to them.  Messages can be mouse clicks, input from some device, a
timer interupt, etc.  These messages are actually how windows multi-tasks.
A windows program accepts a message, responds with some calculations, and
sends off other messages.  Windows itself routes the messages around the
various programs, and at each message, the system can decide who gets
the next message.  Pretty messy really.

There are programs called TAME for windows, which help it detect polloing
DOS programs.  OS/2 (I believe) has similar detection built in, so it
does a better job of guessing (deciphering) what DOS is really trying
to do.  Of course, if your program is nice and uses DOS calls, then OS/2
KNOWS your program is waiting for input, and ignores it until input is ready.

This is a little long winded, but I help it clears up some stuff.  f you
have questions, send Email










-- 
/***************************************************************************\
|  Andrew Jarman                 |   Computer Engineering                   |
|  jarman@bode.ee.ualberta.ca    |   University of Alberta, Canada          |
\***************************************************************************/
Newsgroups: comp.os.os2.misc,comp.windows.ms