That's is true, but it is also a perfect example of where using a lock is probably the wrong way to go. Consider the following instead.<cfif not isDefined("application.init")> <cfset application.myvar = 3 /> <cfset application.othervar = application.myvar /> <cfset application.myvar = application.myvar + 3 /> <cfset application.thirdvar = application.myvar * 4 /> <cfset application.init = 1 /> </cfif>
Surely it's a contrived example, but if multiple threads executed it
concurrently, it's entirely possible that 'othervar' and 'thirdvar' could
contain inappropriate values.
<cfscript>
if(not IsDefined("application.init")) {
init = StructNew();
init.myvar = 3;
init.othervar = myvar;
init.myvar = myvar + 3;
init.thirdvar = myvar + 4; application.init = init;
}
</cfscript>Now the above still has the race condition, but it doesn't actually matter and avoids the lock. Interestingly enough, examples like this tend to perform better when an application variable is initialized too many times vs. just once, but the other threads have to wait on it.
Matt Liotta President & CEO Montara Software, Inc. http://www.MontaraSoftware.com (888) 408-0900 x901
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
