[comp.sys.mac] Life without MMU...

ali@navajo.UUCP (01/29/87)

In article <76000003@uiucdcsp> ericson@uiucdcsp.cs.uiuc.edu writes:
>Just a quick question for you Amiga multi-taskers:
>How can you ensure safe multi-tasking with out an MMU?
>It would seem that any program could write abitrarily into any
>other program's memory - thus causing obvious problems.  Is there
>protection against such on the Amiga, or was the initial poster right
>in that the *program* must insure compatiblity with multi-tasking by
>asking the system for memory or something?
>Just curious,
>Stu

Oh, yes, you're right in saying that any program could write
arbitrary stuff on top of any other program. But it's no problem at all
assuring this. Program written for nonmultitasking systems do not go
out and write things in random memory, right? Same here. 

The main thing to watch out for when programming the Amiga is making 
sure you check that your calls to the OS succeed. The OS is responsible for
maintanence of the resources such as sound channels, memory, I/O ports,
blitter, file accesses, etc. Thus, when call a function such as OpenWindow(),
you should make sure that what it returns is not NULL. That's it! That's
all you have to do, in almost all cases. If you get back NULL, it
probably means the OS could not obtain enough memory for your window.
Same with other resources. Some program is hogging the 6 of the 8 sprites,
and you need 4. So you ask the OS for 4 sprites, and you get back NULL.
At that point you should put up a nice little requester and say you can't
go on, or you should try to use some other method, like using "virtual"
sprites, of which you can have many. If you try to go on assuming you got
the sprites, who knows what might happen. But of course, at that point, it 
would be all your fault.

(Actually, the OS is fairly nice when it comes to managing the resources.
For example, it caches the fonts/libraries etc once it reads them in, and 
then keeps a "usecount" for every task that is accessing that resource.
Even if the usecount falls to zero, the resource is not flushed out of 
memory, unless it is changed on disk or the OS runs out of memory...)

Of course, giving each task its own address space is more important on a
multiuser system than on a single user system like the Amiga. In fact, on the
Amiga, having a single address space might actually be a better solution
as it allows messages to be passed around by reference --- It is not
necessary to duplicate the whole message whenever you send it to someone.
This is a serious efficiency issue as the Amiga operating system relies on
message passing for many of its activities. 

Anyway, to get back to your original questions, YES, programs must 
be careful that they do not go write over other tasks, but NO, this is
presents ne extra work to the programmer except to make sure his/her calls
to the OS succeed. As far as HLL constructs such as malloc() in C or
new() in Pascal go, well, then you really do not have to worry about it
cause the HLL runtime system better be asking the OS for chunks of memory 
as you use it up.  

Hope that answered your question!

Ali Ozer, ali@navajo.stanford.edu

ps. And by the way, I love that "temporary" .signature.