[rescue] Mac Appliance

joshua d boyd rescue at sunhelp.org
Sun Aug 5 00:56:06 CDT 2001


On Sun, Aug 05, 2001 at 01:07:10AM -0400, s at avoidant.org wrote:
> if the PM was preemptive or serial, since we're mostly serial, but if
> keeping a slideshow running while web browsing and playing a CD requires
> preemptive multitasking (does it? I don't know, but i'd think so) then

First playing a CD takes virtually no CPU power, and what CPU power is
required doesn't need to be available in a timely manner.  This is because
the CD plays pretty much autonomously, unless you are trying to read the
CD raw for some reason (like Windows Media Player does).

Other wise, the key to co-operative multitasking is pretty easy for many
programs.  If you program mostly just responds to user events, then you do
your quick processing, and call a function to look for the next user
event.  Doing so generally hands control back to the environment (windows,
PM, MacOS, etc).  If you are playing animation, you get control when a
timer event happens, you display the frame, then look for the next timer
event, thus handing control back to the environment.  Likewise with
downloading network traffic.  You get a packet, process it, then look for
the next, thus handing control back.

The problem comes when you need to do a lot of CPU work, like computing
all the primes from 2 to 2 billion.  Obviously this doesn't depend on
outside events, but it would be unacceptable for your computer to stop
working for 10 days waiting for this program to hand back control.  So,
what you have to do is break the work into small blocks, then process a
block, and set a timer so that you get an event to cause your program to
resume processing.  Alternatively, some environments (windows
specifically) let you look at the event queue without handing control back
to the environtment.

So, instead of 
while (i<1000) i++;
you would do 
while (!PeekMessage() && i <1000) i++;

Anyway, so the example you give is a trivial one to pull off in a
co-operative environment.

-- 
Joshua D. Boyd



More information about the rescue mailing list