[Gas] another dumb (mod)Perl question

Zachary C.Miller wolfgang at wolfgang.groogroo.com
Fri May 25 11:11:18 CDT 2001


> if I make enclosure variable in a class included by the
> main .pm file in a gas project, do those become global
> to each cgi invocation or global to the server (shared
> between all cgi invocations)?
> 
> how would i pick between one and the other?

> is $enclosureHash shared by multiple cgi invocations?

That is a very good question. I would imagine it would be shared. I
would suggest writing some test code. 

Remember that it will only be shared by the CGI's running in a
particular server (there are many servers running at once to allow
processing of simultaneous requests). Any one server only ever
services one request at a time. So there are never the kind of race
conditions for access to "shared" variables as there are in a true
multithreaded situation. So if you are worried about that, never fear.

The important thing is to always initialize your global variables
(including it seems lexicals captured by closures) in the driver .cgi
or in subroutines called by it. Use good programming practice and you
should be safe.

Never trust global variables or captured lexicals to save state
between requests but never trust that they _don't_ have some state in
them. 

I have never thought about this issue specifically before. I'm glad
you brought it up. I'll have to check my code to see whether I've made
this mistake and whether or not it really is a mistake or not.

-- 
Zachary C. Miller - @= - http://wolfgang.groogroo.com/
Today (Friday, May 25) is Towel Day - http://www.towelday.org










More information about the Gas mailing list