Article View: comp.sys.amiga.tech
Article #1553Re: MultiTasking HELP! Please...
From: Chuck McManis
Date: Fri, 06 Oct 1989 18:54
Date: Fri, 06 Oct 1989 18:54
70 lines
3678 bytes
3678 bytes
In article <20974@uflorida.cis.ufl.EDU> misterx@sun ( ) writes:
>1. What is the correct sequence of events for starting a process?
>I have come up with LoadSeg the program, CreateProc it and it should
>go,go,go! But it doesn't. I think I have a problem with the startup
>code provided (in my case) by Lattice. This leads to question 2.
Hmmm, I haven't used CreateProc() but I have used CreateTask() a few
times...
>2. What is necessary in the startup code for a process started by
> another process?
If the process is composed of C code, it should, at a minimum, have
ExecBase initialized (and SysBase). Other than that there are no requirements.
If you aren't using main.c (linking with c.o) then you will want to use
struct ExecBase **SysBase = (struct ExecBase **)4;
struct ExecBase *ExecBase;
ExecBase = *SysBase; /* Get ExecBase loaded up. */
> Do tasks need startup code? What I mean by startup
> code is the absolute minimum needed for a process (or task) to store
> whatever info it needs from the parent (or whereever) so that it doesn't
> munge up.
No, tasks can be nothing more than a subroutine in your program if you so
choose.
>3. What is the correct sequence of events for starting a task?
The easiest way in Lattice to set up a task, it to put the source to your
subroutine in a different file, and declare that routine :
__saveds void
MyRoutine()
{
}
Note that you don't pass it any parameters, and it doesn't return any.
Then you can start it with
CreateTask(MyRoutine, 0, 0); /* I forget the parameters, but you
only need the start address */
> Can a task be LoadSeg()ed in by a process?
It can be, but in general it is easier to make the Task code just a subroutine
in your program. That way it will be LoadSeg'd at when the program runs and
then you don't have to do that yourself.
> Why is he saving A4? Must I always save A4 in all my tasks?
The way Aztec and Lattice C run in "small" model, is to store in A4 a pointer
to the area where all the data is, and then references to variables and such
can just be references off of A4. Unfortunately, when you start a new task
it gets a bright and shiny new set of registers and A4 does *not* point to your
data. So with Aztec you have to use saveA4() to put a copy of A4 somewhere safe
and then geta4() in the task to restore it to its proper value. The __saveds
keyword does this for you in Lattice.
The other caveat for Lattice users is that you have to compile with stackchecking
disabled on the task code because it will have a different stack than the parent
and that will cause problems when the stack code goes to check what it thinks the
boundaries of the stack are.
Of course the easiest way to start a separate process in Lattice is to use
fork(). Just write another program, compile and link it, and then fork it when
you want it to run.
--Chuck McManis
uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"If I were driving a Macintosh, I'd have to stop before I could turn the wheel."
Technical Details
Message-ID:
<125948@sun.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!sun-barr!newstop!sun!pepper!cmcmanisReferences:
<20974@uflorida.cis.ufl.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!sun-barr!newstop!sun!pepper!cmcmanis From: cmcmanis%pepper@Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga.tech Subject: Re: MultiTasking HELP! Please... Message-ID: <125948@sun.Eng.Sun.COM> Date: 6 Oct 89 18:54:06 GMT References: <20974@uflorida.cis.ufl.EDU> Sender: news@sun.Eng.Sun.COM Reply-To: cmcmanis@sun.UUCP (Chuck McManis) Organization: Sun Microsystems, Mountain View Lines: 70