home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1726 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.0 KB  |  107 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: mozart.unx.sas.com!jamie
  3. From: jamie@cdevil.unx.sas.com (James Cooper)
  4. Subject: Re: MsgPorts
  5. Originator: jamie@cdevil.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <DLLtyH.9Gp@unx.sas.com>
  8. Date: Mon, 22 Jan 1996 22:47:05 GMT
  9. X-Nntp-Posting-Host: cdevil.unx.sas.com
  10. References:  <2005.6588T1264T489@Th0r.foo.bar>
  11. Organization: SAS Institute Inc.
  12.  
  13.  
  14. In article <2005.6588T1264T489@Th0r.foo.bar>, christon (Christopher Naas) writes:
  15. >Can someone please tell me what I'm doing wrong here? When I run this program,
  16. >it causes a "Disable/Reboot" requester, and then hangs the machine (hard). If
  17. >I run it with Enforcer enabled, it works fine. I guess I'm doing something not
  18. >quite right, but I can't see what. Please help.
  19. >
  20. >#include <exec/types.h>
  21. >#include <exec/memory.h>
  22. >#include <proto/exec.h>
  23. >#include <proto/dos.h>
  24. >
  25. >struct KMsg
  26. >{
  27. >    struct Message       Message;
  28. >    ULONG                Type;
  29. >};
  30. >struct MsgPort       *mymsgport;
  31. >struct KMsg          *kmsg;
  32. >ULONG                    sig;
  33. >UBYTE                 str[]="<< My test port >>";
  34. >
  35. >void __main (void)
  36. >{
  37. >   if (kmsg = AllocVec (sizeof (struct KMsg), MEMF_ANY|MEMF_CLEAR))
  38. >   {
  39. >      kmsg->Type = 205;
  40. >
  41. >      if (mymsgport = AllocVec (sizeof (struct MsgPort), MEMF_ANY|MEMF_CLEAR))
  42. >      {
  43. >         if (mymsgport = CreateMsgPort ())
  44. >         {
  45.  
  46. You AllocVec() it, then CreateMsgPort() it, blowing away the pointer to
  47. the memory you just allocated.
  48.  
  49. >            mymsgport->mp_Node.ln_Name  = str;
  50. >            mymsgport->mp_Node.ln_Pri   = 0;
  51. >
  52. >            AddPort (mymsgport);
  53. >
  54. >            for (;;)
  55. >            {
  56. >               sig = Wait (SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_C | 1L <<
  57. >mymsgport->mp_SigBit);
  58. >
  59. >               if (sig & SIGBREAKF_CTRL_C)
  60. >               {
  61. >                  break;
  62. >               }
  63. >               else
  64. >               if (sig & SIGBREAKF_CTRL_E)
  65. >               {
  66. >                  PutMsg (mymsgport, (struct Message *)kmsg);
  67. >               }
  68. >               else
  69. >               if (sig & 1L << mymsgport->mp_SigBit)
  70. >               {
  71. >                  kmsg = (struct KMsg *)GetMsg (mymsgport);
  72. >                  Printf ("Got it!  %ld\n", kmsg->Type);
  73. >                  ReplyMsg ((struct Message *)kmsg);
  74. >               }
  75. >            }
  76. >
  77. >            RemPort (mymsgport);
  78. >            DeleteMsgPort (mymsgport);
  79.  
  80. You then DeleteMsgPort() the port you created...
  81.  
  82. >         }
  83. >
  84. >         FreeVec (mymsgport);
  85.  
  86. Then attempt to FreeVec() it?!?
  87.  
  88. >      }
  89. >
  90. >      FreeVec (kmsg);
  91. >   }
  92. >}
  93.  
  94. In other words, CreateMsgPort() allocates the memory for the MsgPort
  95. *for* you, then DeleteMsgPort() frees it back to the systems.  Get rid
  96. of that Alloc/FreeVec code, and it'll probably work as you expected it
  97. to...
  98. -- 
  99. ---------------
  100. Jim Cooper
  101. (jamie@unx.sas.com)                             bix: jcooper
  102.  
  103. Any opinions expressed herein are mine (Mine, all mine!  Ha, ha, ha!),
  104. and not necessarily those of my employer.
  105.  
  106. I'm NOT Politically Correct, but that's because I'm "Sensitivity Challenged."
  107.