Thread View: comp.sys.amiga.tech
2 messages
2 total messages
Started by Kent D. Polk
Sat, 29 Dec 1990 00:41
CreateNewProc
Author: Kent D. Polk
Date: Sat, 29 Dec 1990 00:41
Date: Sat, 29 Dec 1990 00:41
22 lines
1404 bytes
1404 bytes
Please excuse my ignorance here:
If I were to start a thread from a function in my code segment using
CreateNewProc(), can I access variables global to the parent process?
Or would this thread be a full-blown process for which I would need to
set up a shared mem arrangement? The reason for this thread is to
handle gadget input events for a window created by the parent since the
parent is too busy to deal with them in a timely manner. I see I can
pass the window ptr in the CreateNewProc() call. Is this kosher?
Also, I assume I need to set up a message port in the parent process to
send a 'kill' message. Since this thread will be used to handle all
window input events for this window (created by the parent), the window
message port should be adequate for receiving the 'kill' message, no?
I.e., am I on the right track?
Thanks much
Kent Polk: Southwest Research Institute (512) 522-2882
Internet : kent@swrinde.nde.swri.edu
UUCP : $ {cs.utexas.edu, gatech!petro, sun!texsun}!swrinde!kent
Re: CreateNewProc
Author: Rick Schaeffer
Date: Sat, 05 Jan 1991 12:27
Date: Sat, 05 Jan 1991 12:27
99 lines
4004 bytes
4004 bytes
>If I were to start a thread from a function in my code segment using
>CreateNewProc(), can I access variables global to the parent process?
>Or would this thread be a full-blown process for which I would need to
>set up a shared mem arrangement? The reason for this thread is to
>handle gadget input events for a window created by the parent since the
>parent is too busy to deal with them in a timely manner. I see I can
>pass the window ptr in the CreateNewProc() call. Is this kosher?
Yes, you can access globals from the thread process...provided you either
compile with LARGE data model (ie non-relative data addresses) or get the
a4 register loaded as the first thing in the thread process. Do this with
the function "geta4()" in either Manx or Lattice or use the "__saveds"
keyword on the function declaration in Lattice. Note that accessing
globals makes it impossible to make your program resident, though. It's
probably better to pass pointers to everything you need access to from
the thread in the startup message (see below).
>
>Also, I assume I need to set up a message port in the parent process to
>send a 'kill' message. Since this thread will be used to handle all
>window input events for this window (created by the parent), the window
>message port should be adequate for receiving the 'kill' message, no?
CreateNewProc() returns a pointer to the process structure created. This
includes a message port that you can use to kick off the thread. All you
have to do is allocate a message port to be used as the reply port for the
child. An example should suffice:
struct pomsg {
struct Message POm;
/* you can put whatever you want after this */
int rc;
char *cmd;
int *ptr1;
int *ptr2;
} *childmsg;
childmsg = malloc((size_t)sizeof(struct pomsg));
childmsg->POm.mn_ReplyPort = CreateMsgPort();
childmsg->POm.mn_Node.ln_Type = NT_MESSAGE;
childmsg->POm.mn_Node.ln_Pri = 0;
/* at this point you can load up the rest of the elements of childmsg */
ptr1 = "A message for the child"
/* nptags contains a pointer to the function "childprocess" */
child = CreateNewProc(nptags);
/* now pass the child the startup message */
PutMsg(&child->pr_MsgPort,(struct Message *) childmsg);
.
.
.
/* somewhere you want to do a waitport on childmsg->POm.mn_ReplyPort
this can be used to detect the completion of the thread process
or whatever
*/
WaitPort(childmsg->POm.mn_ReplyPort);
/* clean things up */
DeleteMsgPort(childmsg->POm.mn_ReplyPort);
free(childmsg->cmd);
rc = childmsg->rc;
free(childmsg);
/* Now the thread (or child) process */
int childprocess()
{
struct Process *me;
struct pomsg *startupmsg;
int i;
struct Library *DOSBase;
DOSBase = OpenLibrary("dos.library",0L);
/* find our process structure */
me = (struct Process *) FindTask(NULL);
/* Wait for the parent to kick us off */
WaitPort(&me->pr_MsgPort);
/* Get the command to execute */
startupmsg = (struct pomsg *) GetMsg(&me->pr_MsgPort);
/* Now you can do whatever you want with the stuff in the startupmsg */
.
.
.
/* pass the exit code back to the parent */
startupmsg->rc = whatever;
ReplyMsg((struct Message *) startupmsg);
CloseLibrary(DOSBase);
return(0);
}
Note that the return address put on this message by my Amiga UUCP system
is probably bogus. Please reply to the address in my .signature.
--
Rick Schaeffer UUCP: uunet!isc-br.isc-br.com!ricks
E. 13611 26th Ave. ricks@isc-br.isc-br.com
Spokane, Wa. 99216 Phone: (509)928-3533
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads