🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #10335

Re: VANILLAKEYS and various other things

#10335
From: Brian Moffet
Date: Mon, 21 Nov 1988 23:37
95 lines
3375 bytes
In article <8811200120.AA29916@postgres.Berkeley.EDU> dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) writes:
>:In article <1732@scolex> brianm@sco.COM (Brian Moffet) writes:
>:>3) In the same program as #1, I poll a windows IDCMP message
>:>port using GetMsg(W->UserPort).  If I receive a message I will
>:>take some action.   This action may be to go to a subroutine 
>:>which does a Wait(1<<W->UserPort->mp_SigBit).
>:>When this happens, the wait will succeed when there is no new
>:>message.  It apparently sees that there was a message.  I do 
>:>ReplyMsg() properly, so I am not sure what is going on.  
>:>
>:>-=-=-=-=-sample code fragment-=-=-=-=-
>:>	while((mp = GetMsg(up)) == NULL);
>:>	ReplyMsg(mp);
>:>	Wait(1<<up->mp_SigBit);	/* This returns immediatly */
>
>	Completely wrong, the program will freeze!
>
>	(1) You busy wait in the while(), GetMsg() does NOT block, but returns
>	    NULL if no message is ready.  This in itself is a big no-no.

I know it is a no-no.  However, in the hopes for small code fragments
it is okay.  The program will end when a message is recieved.

>
>	(2) You process just a single message and then you Wait().  Contrary
>	    to your comment, Wait() will NOT return immediately every time
>	    and you can get into a lockout situation
>
It will return immediately if there has been a GetMsg() loop
going on before hand (with appropriate ReplyMsg()ing) with
no Wait() calls.   This is my question: Why?

Hmm, people seem to have mistaken what was going on.  I will explain.
I have a program which is a graphics program.  It basically does
calculations etc, for each pixel.  After writing that pixel
I do a GetMsg().  This is for the closewindow gadget.  If this
has happened, I return from the subroutine which is doing the
calculating.   I then will do a Wait() for further action.

It is this wait that returns immediatly.  I then do a GetMsg()
to see what happened, and GetMsg() returns NULL.  the
only thing I can assume is the signal is not cleared.

A better *but longer* example is:

main()
{
	:
	:
	:
	Do_Calc();
	while (1)
	{
		/* this wait will return first time */
		Wait( 1 << mp->Sig_Bit );
		while ( (msg = GetMsg(up)) != NULL )
		{
			class = msg->Class;
			code = msg->Code;
			ReplyMsg(msg);
			Process_Msg(code, class);	/* this will exit */
		}
	}
	:
	:
}

Do_Calc()
{
	:
	:
	ret = 0;
	while (1)
	{
		:
		:
		while ((msg = GetMsg(up)) != NULL)
		{
			ret = 1;
			ReplyMsg(msg);
		}
		if (ret)	return;
	}
}

i had hoped that people would be able to figure out what I was
talking about without so much code, but ah well.   Now, why does the
wait return the first time, but the GetMsg() returns NULL?

brian moffet
-- 
Brian Moffet			{uunet,decvax!microsoft,ucscc}!sco!brianm
 -or-				...sco!alar!brian
"Evil Geniuses for a better tomorrow!"  My fish and company have policies.
					I have opinions.
Technical Details
Message-ID: <1769@scolex>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!sco!brianm
References: <8811200120.AA29916@postgres.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!sco!brianm
From: brianm@sco.COM (Brian Moffet)
Newsgroups: comp.sys.amiga.tech
Subject: Re: VANILLAKEYS and various other things
Summary: Everyones confusion about question. (long)
Message-ID: <1769@scolex>
Date: 21 Nov 88 23:37:22 GMT
References: <8811200120.AA29916@postgres.Berkeley.EDU>
Reply-To: brianm@sco.COM (Brian Moffet)
Organization: The Santa Cruz Operation, Inc.
Lines: 95