[comp.sys.amiga.introduction] Amiga Multitasking

m0154@tnc.UUCP (GUY GARNETT) (01/11/91)

In comp.sys.amiga, there was a question about Amiga multitasking; I
thought I would answer it here ...

Multitasking operating systems can be broken down into two broad
categories, "preemptive" and "cooperative".  The Amiga, as well as
OS/2, Unix, and most mainframes use preemptive multitasking. 
Multifinder for the Mac, and some other computers, use cooperative
multitasking.

Preemptive multitasking is particularly well suited for doing several
things at once (which is why it is used so often); some have been
known to call it "true" multitasking.  Cooperative multitasking is
also valid multitasking, but it is less generally usefull (anything
which can be done on a cooperative multitasking system can also be
done with a preemptive system, in theory, but the reverse is not
true).

Programs on the Amiga have a time limit, or "slice"; when the time
expires, Exec (a part of the Amiga operating system) takes control
away from the running program, and gives it to the next eligible
program.  The time slice is so short that it appears that many
programs are running at once.  Programs can also give up control
volunatrily; usually this happens when the program is waiting for
something, like disk drives, user input, or other "real world" events.
The program in effect says "I have noting to do until someone moves
the mouse (or whatever)", and so Exec starts up another program.  This
helps make efficient use of the computer.

Unlike many preemptive multitasking operating systems, the Amiga has
"real-time response".  This means that external events can be detected
and responded to quickly ("quickly" is a relative term; the Amiga can
respond much faster than most other multitasking systems, although
there are several which are designed to respone even faster still). 
For example, the system can be set up so that a certian program runs
between every frame of video (this is how some programs manage color
cycling).

This post was designed to be a general overview ... more detailed
technical questions can go to comp.sys.amiga.programmer (I have
omitted or glossed over a huge number of things) and discussions of
which is better, Mac, Amiga, Unix, OS/9, OS/2, or whatever can go to
comp.sys.amiga.advocacy.  If anyone has general questions, I'll be
glad to continue the discussion here.

Wildstar

rjc@wookumz.ai.mit.edu (Ray Cromwell) (01/12/91)

  Lets also add to this:

   The Amiga, since it was designed to multitask from the beginning allows
tasks to communicate between one another using Signals, MsgPorts and
Semaphores.  At the lowest level are Signals, which allow tasks to
signal each other and wait for certain signals. (and while waiting,
other tasks are allowed to run making effective use of CPU time.) When a 
task receives a signal it 'Wakes up' and starts running. Using signals,
the Amiga supports Message Ports. These are like signals in that, tasks
may wait for them. Messages offer more however. Messages can contain data, so
tasks can 'share' information instead of holding multiple copies of data, or
reading it from disk. Semaphores are like signals and message ports. They
are primarily used to share public data effectively. Semaphores can
be like auctions. Tasks can 'bid' for the ability to own some data
for a certain period of time and guarantee that another task won't be
trying to access that data while your task is using it. 

 The Amiga's DOS system has another kind of communication called Packets.
Packets are like Message ports, and are mainly concerned with asking
'handlers' to do something, like open a file for you, and read some data.

 I am not an expert on the Mac, so I don't know how the Mac
shares things like Interupts, Devices, Memory, etc.  The main problem
I see for the Mac is, most of the software not written explicitly
for Multifinder won't cooperate enough to make it usuable as a multitasking
system. And even if it does, the MacOS is still at the core, and
Multifinder is just a front-end. (Just like Windows runs on top of MS-DOS)

  To me, true multitasking means multitasking from the beginning.
OS/2 multitasks from the beginning, so does Unix, and fortunately
so does AmigaOS. 

 The Amiga faces a challenge of supporting new video devices in a friendly
manner. (Retargetable Graphics) Since the Amiga didn't have this from the
beginning, it will be hard to make existing software work on newer 
graphic devices. The Mac ironicly got this part right with QuickDraw
(I'm willing to bet, QuickDraw wasn't written to handle multiple tasks
updating the display however.).
 My opinion of course, is I think multitasking is more important than
supporting different display devices.

One last note about multitasking. Systems which support multiple users
usually implement something called 'Aged Multitasking.' This prevents one
user from being stingy and steal lots of processor time from other users. 
Imagine a low priority task like printing the current date periodically, and
a high priority task like a Ray-Tracer. On the Amiga (a single user system)
the Ray Tracer can steal lots of CPU time from a low priority task, even
though the low task doesn't want that much time (since it only runs
periodically.) On 'aged' systems, the OS keeps track of how long
each task runs. If a task gets starved too much, it gives a little extra
CPU time to it. This has a disadvantage in that it can prevent real time
response, and has even more overhead involved in task switching.