[comp.sys.amiga.tech] Children and message ports

hakimian@LUKE.EECS.WSU.EDU (11/03/90)

I have created a child process using CreateProc. In the child I call
FindTask to find my task (process) pointer. I then wait on my process
message port

proc = (struct Process *)FindTask(0);
port = proc->pr_MsgPort;
WaitPort(proc);

In the parent I send a message to the child.

procid = CreateProc(name,pri,seg,stack);
PutMsg(procid,msg);

The result, Task held ...

The eventual guru is 8700004 (not sure on the # of 0). I think this means
bad packet to the dos library. Does it? How did I do that?

This code is in a device driver if that makes any difference.

I have commented out the PutMsg to see if that was the problem. It is.
what is wrong with my PutMsg? Did I miss something?

By the way the child task is running.

Please reply by email, post, homing pigeon, any way you can! Thanks

peter@dbaccess.com (Peter A. Castro) (11/06/90)

in article <9011021641.AA18389@luke.eecs.wsu.edu>, hakimian@LUKE.EECS.WSU.EDU says:
+ 
+ I have created a child process using CreateProc. In the child I call
+ FindTask to find my task (process) pointer. I then wait on my process
+ message port
+ 
+ proc = (struct Process *)FindTask(0);
+ port = proc->pr_MsgPort;
+ WaitPort(proc);
+ 
+ In the parent I send a message to the child.
+ 
+ procid = CreateProc(name,pri,seg,stack);
+ PutMsg(procid,msg);
+ 
+ The result, Task held ...
+ 
+ The eventual guru is 8700004 (not sure on the # of 0). I think this means
+ bad packet to the dos library. Does it? How did I do that?

   Yes, you did.  The CreateProc() function returns a Process structure
   pointer.  You must extract the MsgPort out of this structure and use
   it in your call : PutMsg(procid->pr_MsgPort,msg).
   Look in your friendly include directory for these:
     libraries/dosextens.h, exec/tasks.h

+ 
+ This code is in a device driver if that makes any difference.
+ 
+ I have commented out the PutMsg to see if that was the problem. It is.
+ what is wrong with my PutMsg? Did I miss something?
+ 
+ By the way the child task is running.
 
  BTW: If you linked your child task with standard startup code, it is
  probably waiting for a cli/workbench startup message in the startup code.
  If you have it, look in the Rom Kernel Manuals.  If I remember correctly,
  there are some *corrected* examples which might help you.
+ 
+ Please reply by email, post, homing pigeon, any way you can! Thanks
-- 
Peter A. Castro                   INTERNET: peter@dbaccess.com        // //|
c/o DB Access Inc.                UUCP: {uunet,mips}!troi!peter      // //||
2900 Gordon Avenue, Suite 101     FAX: (408) 735-0328            \\ // //-||-
Santa Clara, CA 95051-0718        TEL: (408) 735-7545             \// //  ||

markv@kuhub.cc.ukans.edu (11/09/90)

> I have created a child process using CreateProc. In the child I call
> FindTask to find my task (process) pointer. I then wait on my process
> message port
> 
> proc = (struct Process *)FindTask(0);
> port = proc->pr_MsgPort;
> WaitPort(proc);
> 
> In the parent I send a message to the child.
> 
> procid = CreateProc(name,pri,seg,stack);
> PutMsg(procid,msg);
> 
> The result, Task held ...
> 
> The eventual guru is 8700004 (not sure on the # of 0). I think this means
> bad packet to the dos library. Does it? How did I do that?
> 
> I have commented out the PutMsg to see if that was the problem. It is.
> what is wrong with my PutMsg? Did I miss something?

Your process message port (pr_MsgPort) is not yours to play with, it
belongs to DOS.  DOS uses it to send DOSPackets back and forth for
your process' file IO.  A non-Handler task should never play with its
process message port.  When you send your message, DOS tries to
interpret it as a DOS packet.  Sooo...

Try creating your own port and sending to it... like: (off the top of
my head, all parameters not guarenteed correct.)

child:

	struct MsgPort	*FooPort;

	FooPort = CreatePort("APORTNAME", 0);
	WaitPort(FooPort);
	...etc...
	when done...
	DeletePort(FooPort);

parent:
	struct MsgPort	*Foo2Port=NULL;
	
	...CreateProc(...)

	while (Foo2Port == NULL) {
		Foo2Port = FindPort("APORTNAME");
		WaitTOF();	/* Dont busy wait, check 30 times p/sec	*/
		WaitTOF();
	}
	PutMsg(Foo2Port, AMessage);

Note that this code is extremely simplified.  The loop around
FindPort() wouldn't be needed if the child could notify a parent with
a signal or message to a MsgPort of the parent.  CreatePort() might
fail too.

> By the way the child task is running.
> 
> Please reply by email, post, homing pigeon, any way you can! Thanks
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum			Only...		\    Good Cheer !!!
Academic Computing Services	       ///	  \___________________________
University of Kansas		     ///  /|         __    _
Bix:	  markgood	      \\\  ///  /__| |\/| | | _   /_\  makes it
Bitnet:   MARKV@UKANVAX		\/\/  /    | |  | | |__| /   \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bartonr@eecs.cs.pdx.edu (Non-Communist) (12/03/90)

peter@dbaccess.com (Peter A. Castro) writes:
>    Yes, you did.  The CreateProc() function returns a Process structure
>    pointer.  You must extract the MsgPort out of this structure and use
>    it in your call : PutMsg(procid->pr_MsgPort,msg).

  Nope, as documented in The AmigaDOS Manual, CreateProc() returns a process
identifier, which is DOS-speak for a MsgPort pointer.  And pr_MsgPort is a
structure, not a pointer as required by PutMsg().