Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!mimsy!oddjob!hao!ames!amdahl!dlb!dana!rap
From: rap@dana.UUCP (Rob Peck)
Newsgroups: comp.sys.amiga
Subject: Re: Comments on the uniqueness of task & window id's
Message-ID: <198@dana.UUCP>
Date: Wed, 22-Jul-87 17:39:30 EDT
Article-I.D.: dana.198
Posted: Wed Jul 22 17:39:30 1987
Date-Received: Sat, 25-Jul-87 01:51:13 EDT
References: <8706260543.AA20346@cogsci.berkeley.edu> <4445@ihlpa.ATT.COM> <6752@steinmetz.steinmetz.UUCP>
Organization: Dana Computer, Inc., Sunnyvale, CA
Lines: 62
Keywords: ID-handler
Summary: Even a full moon...

In article <6752@steinmetz.steinmetz.UUCP>, jesup@mizar.steinmetz (Randell Jesup) writes:
> In article <386@sugar.UUCP> peter@sugar.UUCP (Peter DaSilva) writes:
> >Do what UNIX programs do to create files in /tmp. What you do
> >is: 
> 
> Just make sure digits are unique to the running program.  Otherwise, you get
> into the old 'works except on a full moon when two copies are running at the
> exact same time doing the same thing' problem.  Most problems of unique files
> and ports can be solved with Forbid(), Permit(), and FindPort().

I encountered a problem that couldnt be solved with Forbid(), Permit() and
FindPort().  In particular, I created a master program, that called
test().  test() is something that runs a graphics demo of some kind;
it creates a window of a fixed size, and puts it on a custom screen
whose address it locates by issuing FindPort(myscreen).  An addendum
to the port structure itself is the address of the custom screen.

The master program NOW does:

	Disable();
	port = FindPort(myscreen);
	if(port == 0)
		/* .... create the port if not there ... */
		/* open a custom screen, put the address of
		 * custom screen into addendum to the port;
		 * set users_of_screen = 1
		 */
	Enable();
	test();
	...    	 users_of_screen = users_of_screen -1;

		 (another addendum to the custom port)

	if(users_of_screen = 0) CloseScreen(myscreen);

All programs that are linked with this master routine are supposed to
look first to see if a custom screen exists, create it if not there,
then delete it if they are the last user.

I tried using Forbid() and Permit() in place of Disable(), and Enable(),
but when I tried doing:

	run program1
	run program2	(quickly typed after the first one)

	I got a lot of disk thrashing (as I expected, since it tried
	to load both at once).  And I got TWO custom screens.

(I dont recall exactly how much code I was trying to Forbid() or
Permit() around, but it was, I believe, not quite as large as
indicated above.  Maybe if I had just put Forbid() and Permit()
around finding, then creating a port - then using a Semaphore of some
kind when trying to access the port... but something (don't quite
know what) caused the above technique to pass fine if Disable/Enable
instead of Forbid/Permit while the second program was loading from
the disk.

Just thought I'd mention it.

Email me if you'd like to get a copy of the code.

Rob Peck.	...ihnp4!hplabs!dana!rap