home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 17885 < prev    next >
Encoding:
Internet Message Format  |  1992-12-29  |  3.8 KB

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!rsg1.er.usgs.gov!news.cs.indiana.edu!att!mcdchg!tellab5!chinet!miroc!caw
  2. From: caw@miroc.Chi.IL.US (Christopher A. Wichura)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: HELP!!!!
  5. Distribution: global
  6. Message-ID: <caw.0wbh@miroc.Chi.IL.US>
  7. References:  <BzwyMw.2s0@ccu.umanitoba.ca>
  8. X-NewsSoftware: GRn-beta 1.16g (10.12.92) by Michael B. Smith & Mike Schwartz
  9. MIME-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12. Date: 27 Dec 92 17:54:32 CST
  13. Lines: 75
  14.  
  15. In article <BzwyMw.2s0@ccu.umanitoba.ca> umbadiu0@ccu.umanitoba.ca (Ted Babiuk) writes:
  16. > *sigh*....its 4:09 and I'm at wits end with this....
  17.  
  18. I find that it usually helps to get some sleep at this point.  You wake up
  19. and all your problems seem rediculously simply and you can't figure out why
  20. you couldn't come up with the solution before... :-)
  21.  
  22. > What i'm trying to do is start a new task called 'cycle' which does some
  23. > color cycling while my main program is running.....now.....
  24. >
  25. > Address =LoadSeg("df0:Cycle");  loads the code...and.....
  26. > X = CreateProc("Task_name",Address,priority,stack_size) start it....
  27.  
  28. Reasonable.  However, having the cycle code in a seperate load module is not
  29. necessary.  Instead, just define the cycle code as a function in your c code
  30. that uses __saveds.  I.e., something like:
  31.  
  32. void __saveds CycleProc(void);
  33.  
  34. > but since i need a pointer to the viewport used in the main program in the
  35. > new task 'cycle' to modify colors, how do i pass it???
  36. >
  37. > CreateProc starts a process, but how do you pass data to it....
  38.  
  39. This is easy to do.  When a process is created it automatically has a message
  40. port called pr_MsgPort.  Normally this is not usable by the application since
  41. dos.library uses it for you behind your back and gets very unhappy when
  42. someone dinks around with it when there are packets pending (for example).
  43. However, when your process is first created it isn't doing any dos calls.  So
  44. what you do is
  45.  
  46.     stuct MyMessage {
  47.         struct Message mm_Msg;
  48.         struct ViewPort *mm_ViewPort;
  49.     } msg;
  50.  
  51.     proc = (struct Process *)FindTask(NULL);
  52.     WaitPort(proc->pr_MsgPort);
  53.     msg = (struct MyMessage *)GetMsg(proc->pr_MsgPort);
  54.     viewport = msg->mm_ViewPort;
  55.     ReplyMsg((struct Message *)msg);
  56.  
  57. What the code that is launching the process does is after CreateProc() it
  58. checks to see if the return it got is zero.  If it is then the process wasn't
  59. started to panic as appropriate.  If it's non-zero then you use this pointer
  60. to PutMsg() your msg to the child.  You then wait for the child to reply
  61. before going on.  After this you should never use pr_MsgPort for your own
  62. purposes again.
  63.  
  64. Note that this method is essentially what Workbench itself uses to send a
  65. startup message to programs it launches.
  66.  
  67. You can put anything you want in your startup message.  I often find that is
  68. useful to have a return code field.  The child sets this before replying the
  69. message.  If the child initializes ok then it sets this to zero.  Otherwise
  70. it sets it to some error condition, replys the message and then terminates.
  71. The launching process then checks the return code after the child has replied
  72. the startup message to determine if the child initialized properly and panics
  73. as appropriate when the child fails to start.
  74.  
  75. Unfortunately, I can't recommend any specific pieces of code that implement
  76. this method for you to look at.  I've used it myself, but that's for a
  77. program I 1) haven't released yet and 2) can't release the source to since it
  78. makes use of things that are currently still covered by my NDA agreement with
  79. C= (which also partly explains why reason 1 is true :->).
  80.  
  81. Hope the above helps.
  82.  
  83. -=> CAW
  84.  
  85. --
  86.  
  87. Christopher A. Wichura                Multitasking.  Just DO it.
  88. caw@miroc.chi.il.us  (my amiga)                          ...the Amiga way...
  89. u12401@uicvm.uic.edu (school account)
  90.