[comp.sys.amiga] MANX bugs with Tasking

papa@bacall.UUCP (Marco Papa) (12/14/86)

Has anybody gotten tasking to work with MANX?  All examples from C-A, that work
with Lattice, crash the Amiga with MANX.  CreateTask will always generate
a GURU  and never returns properly.  Try initask.c and tasking.c from the 
Amiga Developer's Newsletter (also posted some time ago on usenet) to see what
I mean.  If anybody has an example of a "working" task creation with MANX, 
please let me know.  I think it is a MANX bug.  Note that all tasking
examples that I have crash with ALL versions of MANX (3.20a through 3.30e).

-- Marco Papa
   Felsina Software

miner@ulowell.UUCP (Richard Miner) (12/17/86)

In article <2226@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
>Has anybody gotten tasking to work with MANX? All examples from C-A, that work
>with Lattice, crash the Amiga with MANX... initask.c and tasking.c from the 
>Amiga Developer's Newsletter...task creation with MANX, please let me know.  
>Note that all tasking examples that I have crash with ALL versions of 
>MANX (3.20a through 3.30e).
>-- Marco Papa
>   Felsina Software
Finaly, someone else with this same problem !  Are'nt any of you 
mini-hackers out there trying to multitask one the Amiga?  I posted a similar
message asking for help and examples over a week ago;  I got one reply from
Matt about starting processes, not what I want to do, and another about
a bug in manx from Milan ZOFKA in Geneva.  Whats up?  Has anyone in 
Weschester had a look at this?  Is it manx or 1.2 or me?  Dale do you have
any ideas?

If you have not seen the metacomco shell, it might be nice at some point
in the future, but seems to have lots of bugs at this point.  And you have
to love those dips at metacomco, IT IS NOT COMPATABLE with CLI!  I mean 
it must have some differnt structures so tha like manx make, that try 
and spawn of other processes, break!

-- 
Rich Miner     ...!wanginst!ulowell!miner   
ULowell, Center for Productivity Enhancement        (617) 452-5000 x2693
HAL hears the Amiga9000 series is not selling. "Please explain Dave. Why 
aren't Amiga9000's selling?" Bowman hesitates, "You aren't IBM compatible."

higgin@cbmvax.cbm.UUCP (Paul Higginbottom GUEST) (12/19/86)

In article <2226@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
>Has anybody gotten tasking to work with MANX? All examples from C-A, that work
>with Lattice, crash the Amiga with MANX... initask.c and tasking.c from the 
>Amiga Developer's Newsletter...task creation with MANX, please let me know.  
>Note that all tasking examples that I have crash with ALL versions of 
>MANX (3.20a through 3.30e).
>-- Marco Papa
>   Felsina Software

Ok - the problem is almost certainly due to a4 not being initialized
correctly.  I have only tried a little on tasks, and gave up in
frustration, and tried Processes which are trivial (LoadSeg, CreateProc,
send 'em a dummy workbench message to kick them into life... voila).

We must work together to lick this problem!  It's as if NO-ONE at
Commodore-Amiga has ever written something that starts up a task!
This of course is impossible (one would think!) because Exec WAS
written by Amiga.  However, note - the WorkBench doesn't multi-task!
Why should I have to WAAAIIIIITT while it loads a directory?  Surely a
task should get fired up to do that while I can do say an Info on another
icon, or format a disk or whatever, but noooo.

[Stepping off bandstand]... for a task to exist it must have....

memory where the program exists
memory where the data exists and the a4 reg (for Manx) must be pointing
into the middle of it.  True is can inheret the a4 of the parent, but
this forces the parent to stick around while the child runs (pain).
memory for a stack (presumably malloc'ed by the parent).

I guess one of the problems is that the C compilers we use assume the
programs are going to run as Processes with CLI structs and other crud
associated with them.  Therefore I suspect _main() and _exit()/exit()
will need to be re-written.  Comments?  If this can be accomplished,
it would seem to me that a program with this special _main etc could be
LoadSeg'ed, given a stack, and AddTask'ed.  Comments?

I'd give a lot for two things ---- decent BCPL and tasking documentation
and EXAMPLES OF WORKING PROGRAMS!  However that might not be sufficient
either due to the differences in Manx/GreenHills/Lattice.

	Sigh,
		Paul.

Disclaimer: I work for myself and my opinions are my own.

carolyn@cbmvax.cbm.UUCP (Carolyn Scheppner) (12/19/86)

In article <1146@cbmvax.cbmvax.cbm.UUCP> higgin@cbmvax.UUCP (Paul Higginbottom GUEST) writes:
>In article <2226@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
>>Has anybody gotten tasking to work with MANX? All examples from C-A, that work
>>with Lattice, crash the Amiga with MANX... 
>...
>We must work together to lick this problem!  It's as if NO-ONE at
>Commodore-Amiga has ever written something that starts up a task!

   I've created sub-tasks with no problem using Lattice by calling the
CreateTask routine in Amiga.lib.  For those who can't link with Amiga.lib,
the C source is in our RK manual Vol 2, A/W's RK exec manual.

   There certainly are people here who have started tasks, but most
of us use Lattice or Greenhill's.  If you can't create a task with
Manx, call Manx.  If you're not talking about sub-tasks, but rather
starting a whole program as a Task, it should be possible as long
as the program does not use AmigaDOS in any way or access any disk
resident libraries.  It would also have to have either no startup
code, or special startup code, not the normal startup which
uses AmigaDOS and expects things passed to it by DOS or WB.

carolyn
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CBM   >>Amiga Technical Support<<
                     UUCP  ...{allegra,caip,ihnp4,seismo}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

andy@cbmvax.cbm.UUCP (Andy Finkel) (12/19/86)

In article <1146@cbmvax.cbmvax.cbm.UUCP> higgin@cbmvax.UUCP (Paul Higginbottom GUEST) writes:
>In article <2226@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
>>Has anybody gotten tasking to work with MANX? All examples from C-A, that work
>>with Lattice, crash the Amiga with MANX... initask.c and tasking.c from the 
>>Amiga Developer's Newsletter...task creation with MANX, please let me know.  
>>Note that all tasking examples that I have crash with ALL versions of 
>>MANX (3.20a through 3.30e).
>>-- Marco Papa

>Ok - the problem is almost certainly due to a4 not being initialized
>correctly.  I have only tried a little on tasks, and gave up in
>frustration, and tried Processes which are trivial (LoadSeg, CreateProc,
>send 'em a dummy workbench message to kick them into life... voila).
>
>We must work together to lick this problem!  It's as if NO-ONE at
>Commodore-Amiga has ever written something that starts up a task!

Ahem.  I can fire up tasks quite well, under either Lattice or
Greenhills.  

>This of course is impossible (one would think!) because Exec WAS
>written by Amiga.  However, note - the WorkBench doesn't multi-task!
>Why should I have to WAAAIIIIITT while it loads a directory?  Surely a
>task should get fired up to do that while I can do say an Info on another
>icon, or format a disk or whatever, but noooo.

While the workbench doesn't use multitasking, it does allow it. For example,
you can bring up a directory while a format is going on.

There are reasons to view certain operations as atomic.  Sometimes
it doesn't make sense to fire off subtasks within a program.
Sometimes it does.  But workbench doesn't forbid multitasking.

>I'd give a lot for two things ---- decent BCPL 
I understand MetaCompCo is coming out with their BCPL compiler
on the Amiga.  I'm not sure if you'll be happy once you buy it, but...

and tasking documentation
>and EXAMPLES OF WORKING PROGRAMS!  However that might not be sufficient
>either due to the differences in Manx/GreenHills/Lattice.
Right.  Examples can be found on the net, on disks we've given out,
on BIX, and in the Fish collection.  

I guess its going to take someone who understands how the Manx compiler
works to convert them.

>	Sigh,
>		Paul.

	Sigh, also,
		andy finkel
-- 

			andy finkel
			Commodore/Amiga
			{ihnp4|seismo|allegra}!cbmvax!andy
		or	 pyramid!amiga!andy

Any expressed opinions are mine; but feel free to share.

I disclaim all responsibilities, all shapes, all sizes, all colors.

"Never make anything simple and efficient when it can be complex and wonderful."

phillip@cbmvax.cbm.UUCP (Phillip Lindsay) (12/19/86)

> >>Has anybody gotten tasking to work with MANX? [...cut]
> >>-- Marco Papa

This is a problem related to the A4 register used as a base register, I believe
the problem is apparent in the small-code/data models and not in large code/data
models. (ie. "cc +cd foo.c" will compile using large models) 

In the interest of people screaming about Manx and tasks I make the following
re-posting from well!crunch: (I don't think crunch and manx will mind...)

AMIGA-MANX-FIX
--------------

From: crunch@well.UUCP (John Draper)

    I got permission from Jim Goodnough from Manx to publish the following
information.   Manx C has some problems when spawning tasks.   It appears
that the A4 register is improperly set.    Below is some code that you
need to add to get multi-tasking to work properly.

   Before calling the "AddTask" function,  it is necessary to call the
sava4() function which is listed below.    Then, in your Task,  you need to 
call geta4().   The code below can be included in your source or be
seperately compiled and linked into your program.

----------------- cut here ----------------
/*====================================================================
  Get and Save A4 Regs to fix a manx bug
=====================================================================*/
 #asm
a4sav  dc.l    0
 
        public  _sava4
_sava4
        lea     a4sav,a0
        move.l  a4,(a0)
        rts
 
        public  _geta4
_geta4
        move.l  a4sav,a4
        rts
 #endasm


  Another problem with the Manx system is in the debug program.   It is not
possible to set a breakpoint in a separate task.    The "db" program will
only call the "guru".   Manx also doesn't have a "kprintf" function,  so
using intermediate print statements to debug code is a royal pain.

  Jim cooked up a "kprintf" routine, and it's listed below.   The "kprintf"
function only works if you connect an external terminal to the serial port
or another computer.   Then all your debug diagnostic printing can take 
place on the external computer.   I use the Macintosh as an external
computer and use the ImageWriter cable connected to the serial port on the
Amiga.   I use MacTerminal because it has an extra large capture buffer and
send all my debug messages over to the Mac screen.   It works very well.
I also hacked up the "avail.c" program and modified it to use "kprintf"
so I can keep track of memory allocations so I can make sure I release it
when done.    It works very well and painlessly.   My only problem seems
to be that I forget to cast the sizeof's to (long)'s.   Which really
messes things up.    The "kprintf" code is listed below.

----------------- cut here -----------------
/*
 *      This is a debug library which interacts directly with the Serial
 *      port.
 *
 *      Functions are:
 *                     kprintf(fmt, arg1, arg2,....);
 *                                    kputchar(char);
 *                                     kputs(string);
 */
 
kprintf(fmt, args)
char *fmt;
int args;
{
        int kputchar();
 
        return(format(kputchar, fmt, &args));
}
 
kputs(str)
char *str;
{
        while (*str)
                kputchar(*str++);
        kputchar('\n');
}
 
#asm
        public  _LVORawPutChar
        public  _kputchar
_kputchar
        move.l  4,a6
        move.w  4(sp),d0      ;make the 'w' an 'l' if using c32.lib
        cmp.b   #$a,d0
        bne.s   .1
        jsr             _LVORawPutChar(a6)
        move.l  #$d,d0
.1
        jmp             _LVORawPutChar(a6)
#endasm
 


-------------- cut here ----------------


  I hope this makes your programming effort easier.  It sure has made it
better for me.

Regards:   John Draper
Programmers Network ( A programmers Guild)
"The place where we all live and learn"
.....ihnp4!ptsfa!well!crunch

/* EOF */
 
-- 
==============================================================================
  Phillip Lindsay - Commodore Business Machines - Amiga Technical Support
  UUCP: {ihnp4|seismo|caip}!cbmvax!phillip      - Phone: (215) 431-9180
  No warranty is implied or otherwise given in the form of suggestion or 
  example. Any opinions found here are of my making. 	/* eof */

papa@bacall.UUCP (Marco Papa) (12/22/86)

> In article <1146@cbmvax.cbmvax.cbm.UUCP> higgin@cbmvax.UUCP (Paul Higginbottom GUEST) writes:
> >In article <2226@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
> >>Has anybody gotten tasking to work with MANX? All examples from C-A, that work
> >>with Lattice, crash the Amiga with MANX... 

Carolyn writes:
> Manx, call Manx.  If you're not talking about sub-tasks, but rather
> starting a whole program as a Task, it should be possible as long
> as the program does not use AmigaDOS in any way or access any disk
> resident libraries.  It would also have to have either no startup
> code, or special startup code, not the normal startup which
> uses AmigaDOS and expects things passed to it by DOS or WB.
>

As I was saying in my original message, I had NO problem using tasks with
Lattice.  All the programs I tried, my own, the examples from the Amiga
Developer's newsletter and the ones posted on usenet, they all work fine with
Lattice. NONE of them works with ANY version of MANX, using ANY menory model.
Someone suggested to use +c and +D (large code and large data) but this did
not make any difference.  I left messages to Jim Goodnow at well!manx but got 
no reponse whatsoever.  If you have problems with MANX and multitasking
send him mail.  Maybe if he gets a bunch of complaints, he might fix
it.

-- Marco Papa
   Felsina Software
 

papa@bacall.UUCP (Marco Papa) (12/22/86)

I write:
> > >>Has anybody gotten tasking to work with MANX? [...cut]
> > >>-- Marco Papa

Phillip Lindsay writes: 
> This is a problem related to the A4 register used as a base register, I believe
> the problem is apparent in the small-code/data models and not in large code/data
> models. (ie. "cc +cd foo.c" will compile using large models) 
> 
> In the interest of people screaming about Manx and tasks I make the following
> re-posting from well!crunch: (I don't think crunch and manx will mind...)
> 
> AMIGA-MANX-FIX follows

Thanks Phil!  Why this didn't get fixed in the beta 3.30e, I don't know.
Hopefully it will be fixed in 3.40. Now the problem.  Does the patch works
also if done before/after CreateTask (which calls AddTask)?  If it does not,
then only people like me that have the "source" for CreateTask can fix it.
I will try this tonight and see what happens.

-- Marco Papa
   Felsina Software

papa@bacall.UUCP (Marco Papa) (12/22/86)

My response to Phil Lindsay patch was as follows:
> 
> Thanks Phil!  Why this didn't get fixed in the beta 3.30e, I don't know.
> Hopefully it will be fixed in 3.40. Now the problem.  Does the patch works
> also if done before/after CreateTask (which calls AddTask)?  If it does not,
> then only people like me that have the "source" for CreateTask can fix it.
> I will try this tonight and see what happens.
> 

I tried this tonight, and in fact it works.  I was using small data and small
code (NO switches +c and +d).  I put sava4() right before CreateTask() and
geta4() as the FIRST instruction of the new task and everything worked.
So, one does not ned the source to CreateTask anyway.

-- Marco Papa
   Felsina Software

higgin@cbmvax.cbm.UUCP (Paul Higginbottom GUEST) (12/24/86)

In article <2233@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
>I write:
>> > >>Has anybody gotten tasking to work with MANX? [...cut]
>> > >>-- Marco Papa
>
>Phillip Lindsay writes: 
>> This is a problem related to the A4 register used as a base register, I believe
>> the problem is apparent in the small-code/data models and not in large code/data
>> models. (ie. "cc +cd foo.c" will compile using large models) 
>> 

Large model won't work if you want to use anything in the linkable libraries
which were compiled "small model".

>> In the interest of people screaming about Manx and tasks I make the following
>> re-posting from well!crunch: (I don't think crunch and manx will mind...)
>> 
>> AMIGA-MANX-FIX follows
>

This fix wasn't quite right since (at least under 3.30e) the front end
already contains a geta4() routine and saves a4 off automatically.
By front end I mean crt0.a68 which is linked in the front of every C
program written (along with _main.c).

So, all you need to do is:

	geta4();

as the first thing in your task.

The REAL problem however, is as follows, and this doesn't have anything to
do with Manx.  You'll note in the DeleteTask() source (in RKM v2) that
it says "doesn't handle self-deletion properly."  Well I'm not
surprised.  To get a task started, you simply alloc a task structure
and a stack for the task, init the task structure, and call AddTask
either with a starting pc of some function in the program itself (basically
making a sub-task part of the same progra), or with a shifted BPTR
returned from a LoadSeg'ed program module (which will need a special
front end by the way, or it won't get hopping, but that's another issue).

Anyway, supposing you have a task running - how does it end?  When it
"rts"'s - Exec does a RemTask if you don't have some special cleanup
code, but HOW is the task structure and stack going to be freed?  If it
is done by the parent (the program that created it), how is the parent
to know when the child (sub task) has finished?  The only way I can
think of is that the parent must create a message port, and the child
sends of a message saying "I'm finished" just before ending, so that
once the parent receives the message (which it WON'T reply to of course),
it can then go ahead with freeing up the stack and task structure.

This to me still isn't ideal - I'd like to be able to get a task going
and let the task deal with termination itself, i.e., exist independently,
without the need for the parent to stick around to cleanup after its
offspring (how metaphoric).  I'd like some ideas on this if anyone
has any.

Summary
-------
	I can create a task, but without going to the message port solution
outlined above, the program loses the memory allocated for task structure
and stack every time because the parent can't free it (through not knowing
when the child has finished).
	I tried having the optional FinalPC code do it for the child, but
(I guess) as soon as it tries to free its own stack, its history (i.e., guru).

		Aside,
			Best Wishes to all and their Amigas over the
			Holiday season.


		Paul Higginbottom.

Disclaimer: I work for myself, and my opinions are my own.

>Thanks Phil!  Why this didn't get fixed in the beta 3.30e, I don't know.
>Hopefully it will be fixed in 3.40. Now the problem.  Does the patch works
>also if done before/after CreateTask (which calls AddTask)?  If it does not,
>then only people like me that have the "source" for CreateTask can fix it.
>I will try this tonight and see what happens.
>
>-- Marco Papa
>   Felsina Software

papa@bacall.UUCP (Marco Papa) (12/28/86)

> In article <2233@bacall.UUCP> papa@bacall.UUCP (Marco Papa) writes:
> >> > >>Has anybody gotten tasking to work with MANX? [...cut]
> >> > >>-- Marco Papa
> >
> >Phillip Lindsay writes: 
> >> This is a problem related to the A4 register used as a base register, I believe
> >> the problem is apparent in the small-code/data models and not in large code/data
> >> models. (ie. "cc +cd foo.c" will compile using large models) 
> >> 
> >> In the interest of people screaming about Manx and tasks I make the following
> >> re-posting from well!crunch: (I don't think crunch and manx will mind...)
> >> 
> >> AMIGA-MANX-FIX follows
> >

Paul Higginbottom writes:
> 
> This fix wasn't quite right since (at least under 3.30e) the front end
> already contains a geta4() routine and saves a4 off automatically.
> By front end I mean crt0.a68 which is linked in the front of every C
> program written (along with _main.c).
> 
> So, all you need to do is:
> 
> 	geta4();
> 
> as the first thing in your task.
>

I have both 3.20a and 3.30e and Paul fix is definetely right: All in all:

1. If you have MANX 3.20a you need to call sava4() before calling CreateTask
   or Addtask(), and call geta4() as the first instruction of the child task.
   You also have to compile the source from Phil, since this is not available
   in the librariy. 

2. If you have MANX 3.30e or later, you do not have to call sava4(), but still
   have to call geta4() in the subtask.  This time do not include any code,
   since geta4() is included in the library.

Hopefully all of this is going to be well explained in the new MANX 3.40
manual.  Gee, I did not know that I would ahve opened such a can of worms with
my original posting.  Now everybody knows how to do tasks (with 
MANX, Lattice or your favourite compiler).

  -- Marco Papa
     Felsina Software
 

phillip@cbmvax.cbm.UUCP (Phillip Lindsay) (12/29/86)

> 
> Summary
> -------
> 	I can create a task, but without going to the message port solution
> outlined above, the program loses the memory allocated for task structure
> and stack every time because the parent can't free it (through not knowing
> when the child has finished).
> 	I tried having the optional FinalPC code do it for the child, but
> (I guess) as soon as it tries to free its own stack, its history (i.e., guru).
> 
> 		Paul Higginbottom.
> 
> Disclaimer: I work for myself, and my opinions are my own.
> 
Paul - In the task control block there is a memory list. You can stick your
stack, TCB allocation there...and when you do a RemTask(0) the memory will be 
de-allocated for you. -phil
==============================================================================
  Phillip Lindsay - Commodore Business Machines - Amiga Technical Support
  UUCP: {ihnp4|seismo|caip}!cbmvax!phillip      - Phone: (215) 431-9180
  No warranty is implied or otherwise given in the form of suggestion or 
  example. Any opinions found here are of my making. 	/* eof */