🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: CloseWindowSafely() ???

#11235
From: Jim Mackraz
Date: Sun, 29 Jan 1989 20:33
56 lines
2727 bytes
In article <11640008@hpfcdc.HP.COM> cunniff@hpfcdc.HP.COM (Ross Cunniff) writes:
)Regarding the AmigaMail function CloseWindowSafely() (which I
)can't seem to find anywhere (hint,hint)), I have come up with
)something that seems to work for windows which are sharing IDCMPs:
)
)	ILock = LockIBase( 0 );
)
)		while( Msg = GetMsg( Win->UserPort ) ) {
)		    ReplyMsg( Msg );
)		}
)		Win->UserPort = NULL;
)		CloseWindow( Win );
)
)	UnlockIBase( ILock );

)My questions about this are:
)
)	1. Will this guarantee no GURUs?  (The code without the
)	   LockIBase and the while( Msg = Getmsg() ) will GURU
)	   if there are any pending messages to Win)

No guarantee, but I can assure you there is a potential for deadlocks.

)	2. Is it desirable to have the CloseWindow inside the
)	   LockIBase()/UnlockIBase() protected region?  It seems
)	   to work and has caused no problems, but it makes me
)	   nervous to call Intuition functions inside the
)	   protected region.  On the other hand, there may
)	   be a window (pun intended) of vulnerability if the
)	   UnlockIBase() is placed BEFORE the CloseWindow().

As well it should make you nervous.  The purposes of LockIBase() are explicitly
stated: for quick inspection of the public data of IntuitionBase which would
not otherwise be safe.

Making assumptions about Intuition's locking protocol is not wise in the least.

The problem with your example is that it clears ALL the messages from the port,
even those intended for windows other than the one you are closing.  Indeed,
you must get the messages out of there for the window you close, also insuring
that no others will be sent and that Intuition won't deallocate the port
that other windows are using.  Use CloseWindowSafely().  There's been a modification
to it to check that you don't pass a NULL window, or something, so the
copy I have on line isn't the best.  If it doesn't appear magically soon, I'll
try to get it posted.

)	3. There is no 3.

Good, then you only missed 2 out of 2. ;^)

)					Ross Cunniff
-- 
Jim Mackraz, I and I Computing	   	"Like you said when we crawled down
{cbmvax,well,oliveb}!amiga!jimm          from the trees: We're in transition."
							- Gang of Four
Opinions are my own.  Comments are not to be taken as Commodore official policy.
Technical Details
Message-ID: <3291@amiga.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!oliveb!amiga!jimm
References: <11640008@hpfcdc.HP.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!oliveb!amiga!jimm
From: jimm@amiga.UUCP (Jim Mackraz)
Newsgroups: comp.sys.amiga.tech
Subject: Re: CloseWindowSafely() ???
Message-ID: <3291@amiga.UUCP>
Date: 29 Jan 89 20:33:22 GMT
References: <11640008@hpfcdc.HP.COM>
Reply-To: jimm@cloyd.UUCP (Jim Mackraz)
Organization: Commodore-Amiga Inc, Los Gatos CA
Lines: 56