home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: mozart.unx.sas.com!jamie
- From: jamie@cdevil.unx.sas.com (James Cooper)
- Subject: Re: MsgPorts
- Originator: jamie@cdevil.unx.sas.com
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <DLLtyH.9Gp@unx.sas.com>
- Date: Mon, 22 Jan 1996 22:47:05 GMT
- X-Nntp-Posting-Host: cdevil.unx.sas.com
- References: <2005.6588T1264T489@Th0r.foo.bar>
- Organization: SAS Institute Inc.
-
-
- In article <2005.6588T1264T489@Th0r.foo.bar>, christon (Christopher Naas) writes:
- >Can someone please tell me what I'm doing wrong here? When I run this program,
- >it causes a "Disable/Reboot" requester, and then hangs the machine (hard). If
- >I run it with Enforcer enabled, it works fine. I guess I'm doing something not
- >quite right, but I can't see what. Please help.
- >
- >#include <exec/types.h>
- >#include <exec/memory.h>
- >#include <proto/exec.h>
- >#include <proto/dos.h>
- >
- >struct KMsg
- >{
- > struct Message Message;
- > ULONG Type;
- >};
- >struct MsgPort *mymsgport;
- >struct KMsg *kmsg;
- >ULONG sig;
- >UBYTE str[]="<< My test port >>";
- >
- >void __main (void)
- >{
- > if (kmsg = AllocVec (sizeof (struct KMsg), MEMF_ANY|MEMF_CLEAR))
- > {
- > kmsg->Type = 205;
- >
- > if (mymsgport = AllocVec (sizeof (struct MsgPort), MEMF_ANY|MEMF_CLEAR))
- > {
- > if (mymsgport = CreateMsgPort ())
- > {
-
- You AllocVec() it, then CreateMsgPort() it, blowing away the pointer to
- the memory you just allocated.
-
- > mymsgport->mp_Node.ln_Name = str;
- > mymsgport->mp_Node.ln_Pri = 0;
- >
- > AddPort (mymsgport);
- >
- > for (;;)
- > {
- > sig = Wait (SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_C | 1L <<
- >mymsgport->mp_SigBit);
- >
- > if (sig & SIGBREAKF_CTRL_C)
- > {
- > break;
- > }
- > else
- > if (sig & SIGBREAKF_CTRL_E)
- > {
- > PutMsg (mymsgport, (struct Message *)kmsg);
- > }
- > else
- > if (sig & 1L << mymsgport->mp_SigBit)
- > {
- > kmsg = (struct KMsg *)GetMsg (mymsgport);
- > Printf ("Got it! %ld\n", kmsg->Type);
- > ReplyMsg ((struct Message *)kmsg);
- > }
- > }
- >
- > RemPort (mymsgport);
- > DeleteMsgPort (mymsgport);
-
- You then DeleteMsgPort() the port you created...
-
- > }
- >
- > FreeVec (mymsgport);
-
- Then attempt to FreeVec() it?!?
-
- > }
- >
- > FreeVec (kmsg);
- > }
- >}
-
- In other words, CreateMsgPort() allocates the memory for the MsgPort
- *for* you, then DeleteMsgPort() frees it back to the systems. Get rid
- of that Alloc/FreeVec code, and it'll probably work as you expected it
- to...
- --
- ---------------
- Jim Cooper
- (jamie@unx.sas.com) bix: jcooper
-
- Any opinions expressed herein are mine (Mine, all mine! Ha, ha, ha!),
- and not necessarily those of my employer.
-
- I'm NOT Politically Correct, but that's because I'm "Sensitivity Challenged."
-