Thanks Ray...this is helping me get a clearer picture on locking in MX.
Maybe a couple of examples might help me, to be sure. Please let me
know if my assessment is correct or not. Thanks again.
1)
<cfset application.dsn = "foo"/>
Does NOT need to be locked.
2)
<cfif isDefined( 'url.clearCart' )>
<cfset session.cart = arrayNew(1)/>
</cfif>
DOES need to be locked because other threads could be reading from
session.cart.
3)
<cfset session.breadCrumb = arrayAppend( session.breadCrumb, 'Product
Details' )/>
DOES need to be locked because other threads could be reading or writing
to session.breadCrumb.
4) (In a CFC that has been instantiated into the application scope)
<cffunction name="init">
<cfset myInstanceVar = "default" />
</cffunction>
Does NOT need to be locked (either inside the CFC or where the init()
method is called) assuming that the init() method is a constructor and
will only be called once, when that object is instantiated.
5) (In a CFC that has been instantiated into the application scope)
<cffunction name="setInstanceVar">
<cfargument name="aValue"
<cfset myInstanceVar = arguments.aValue />
</cffunction>
DOES need to be locked (either inside the CFC or where the
setInstanceVar() method is called) if other threads could be reading
from myInstanceVar.
Am I close, or way off base? Thx.
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Raymond Camden
> Sent: Wednesday, December 03, 2003 5:15 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [CFCDev] Basic CFC Design Question
>
> > But Ray, in the example you used, you are clearly NOT sure
> > that your variable will only be written to once. Right?
>
> No. Again, it is a waste of time to set application.dsn more
> than once, however, it's is a very trivial waste of time.
>
> > So if you did:
> > <cfif not isDefined( 'application.dsn' )>
> > <cfset application.dsn = "foo"/>
> > </cfif>
> >
> > Then you would not need to lock it.
>
> That is not what you said though. The code above CAN be run
> twice, because two (or more) threads can read the isDefined
> line and both see false. Again though, its not a big deal.
>
>
> >But doing it the way you
> > show, with no check for it's presence before writing to it,
> > you would need to lock it, and then lock all reads to it as
> > well. Correct?
>
> No. Again, assuming MX, it doesn't matter if N threads read
> the value while its being set if it is static.
----------------------------------------------------------
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]