[thelist] cflock reads?

.jeff jeff at members.evolt.org
Mon Jan 21 16:21:10 CST 2002


chris,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Chris Evans
>
> 1) Because shared variables are stored in memory,
>    simultaneous reads and writes will cause memory
>    errors that crash the server.  I've never heard
>    a really good reason why CF doesn't lock these
>    internally, transparent to the programmer, but
>    that's the way it goes.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

there's a very good reason the server doesn't handle it transparent to the
user -- the user is in a better position to know how to best handle locking
based on how the application is written.  consider you've got an application
with shared scope reads and writes all over the place.  if the server did it
automatically it would have to wrap each reference with a lock *and* try to
figure out which type of lock it needed (which would be just as bad as
performance-wise if the user just went through their code and went to
wrapping each instance he found with a lock).  however, as a developer that
knows something about performance and shared scope locking issues, i can
write the shared scope to a local scope once at the beginning and then back
to the shared scope once at the end and manage those locks myself.  here's
another good example using code:

<cflock scope="server" type="readonly" timeout="10" throwontimeout="no">
  <cfset local.server = StructNew()>
  <cfset local.server.coldfusion = StructNew()>
  <cfset local.server.coldfusion.productversion=
server.coldfusion.productversion>
  <cfset local.server.os = StructNew()>
  <cfset local.server.os.version = server.os.version>
</cflock>

if the server did it automatically, it'd have to perform a separate lock for
each one, essentially like this:

<cflock scope="server" type="readonly" timeout="10" throwontimeout="no">
  <cfset local.server = StructNew()>
</cflock>
<cflock scope="server" type="readonly" timeout="10" throwontimeout="no">
  <cfset local.server.coldfusion = StructNew()>
</cflock>
<cflock scope="server" type="readonly" timeout="10" throwontimeout="no">
  <cfset local.server.coldfusion.productversion=
server.coldfusion.productversion>
</cflock>
<cflock scope="server" type="readonly" timeout="10" throwontimeout="no">
  <cfset local.server.os = StructNew()>
</cflock>
<cflock scope="server" type="readonly" timeout="10" throwontimeout="no">
  <cfset local.server.os.version = server.os.version>
</cflock>

that would be quite inefficient -- probably moreso than not having the locks
in there to begin with.

just my 2¢,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list