Shared variables such as application and session should be locked,
however the lock really only needs to be there on a write. Writing to a
shared variable can cause the system to hang or enter a state of
confusion, hence the locking of the variable.

However although recommended to lock all reads and writes, I personally
have never done it on a read of said such variables. It is also very
safe to do the following...

<cflock>
 <cfset application.test = "Test">
 <cfoutput>Hello</cfoutput>
</cflock>

All it means is that while this bit of code is being run, nobody else
can access this bit of code until this process has released the lock. If
2 applications write to a variable at the exact same time (rare, but
very possible) CF can enter a state of deadlock and will require the
server to be restarted.

For more information on this, consult the manual about the attributes
scope and type that allow the variable to be read only or exclusive and
to define the type of variable it is. For example is it an application,
server or even session scope.

But the point is well within what has been discussed many times on this
list, should we or should we lock reading of variables. Like I said I
don't when reading them, and have never had any problems (touch wood)
with this method.

But there are many reasons why one should use application scope
variables, for example to determine how many people are actually logged
into a membership system as a good example.
 


-----Original Message-----
From: Shawn Regan [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, 27 June 2002 12:18 AM
To: CF-Talk
Subject: RE: What is the best variable scope?

Why do you need to lock it?

Shawn Regan


______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to