Sounds like some relaxing reading for the Labor Day weekend... I can hear
my wife now... "What are you reading?" .. Just trying to brush up on the
finer points of avoiding corrupted memory & race conditions.
-----Original Message-----
From: Zachary Bedell [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 31, 2000 10:54 AM
To: '[EMAIL PROTECTED]'
Subject: RE: YAFLQ (Yet Another "Fine" Locking Question)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You'll want to modify that code a bit...
You're better off avoiding any locks around things like CFQUERY that
can take a while to run.
Just skimming the code, it looks like you're READING
session.susertype and session.suser_id; and you're not WRITING to
anything. Am I right?
If that's the case, your best bet would be something like:
<cflock scope="session" type="readonly" ...>
<cfset suser_id = session.suser_id>
<cfset susertype = session.susertype>
</cflock>
<!--- The rest of your code here with no locks, but using the local
suser... variables instead of the session.suser... ones. --->
You always want to lock the absolute minimum amount of code.
Otherwise all of the multithreaded power of CFAS is choked down to a
single thread when it processes your locked sections of code.
Certainly lock everything that needs to be locked, but don't lock a
single line more than that.
If anyone's interested in some extra reading, find some decent
references on shared memory locking in a multithreaded programming
environment. The best stuff would probably be for the C++ language,
but you should be able to get the concepts of exactly what needs to
be locked to avoid corrupted memory & race conditions. Technically a
"scripting language" shouldn't have to expose this kind of low level
stuff to the end user, but.... Any books or online tutorials on BSD
IPC should be helpful. I'll see if I can dig up some of the ones
I've found & will post them here if there's an interest.
Best regards,
Zac Bedell
> You are doing an exclusive lock
> on those variables.
>
> No where are you setting any of those
> session variables so the exclusive
> lock is not needed.
>
> Just
> <CFLOCK SCOPE="session" timeout="30" TYPE="ReadOnly">
> <cfif #session.susertype# is not "admin">
> <cfquery name="get_message" datasource=#variable.ds#>
> select message_text
> from vcross.messages
> where
> <cfif #session.susertype# is "student"> [LOCK HERE?]
> message_type = 'student'
> </cfif>
> <cfif #session.susertype# is "faculty"> [LOCK HERE?]
> message_type = 'faculty'
> </cfif>
> </cfquery>
>
> <cfquery name="get_specific_message" datasource=#variable.ds#>
> select message_text
> from vcross.messages
> where message_type = 'specific'
> and user_id = #session.suser_id# [LOCK HERE?]
> </cfquery>
> </cfif>
> </CFLOCK>
>
> No nesting you just Lock the session scope to read only
> do your processing of session variables and release
> the lock.
>
> Were you to do *ANY* setting of the variables
> you would need to make the lock exclusive.
>
> The only time a readonly lock actually has to wait
> is when there is an exclusive lock on the scope
> then thye wait for the exclusive lock to be
> released and they read the variables.
> Otherwise readonly locks can 'peek' at the variables
> all day long until an exclusive lock gets ahold
> of a scope :)
>
>
> Also just to nit pick doing string comparison
> is going to be more effecient using the
> Compare function :)
>
> try this instead of
> <CFIF stringFoo is "faculty">
>
> <CFIF NOT Compare(session.suserType, "faculty")>
> <!--- Strings are equal do something --->
> </CFIF>
>
> The reason you use the NOT Compare syntax is because
> If the strings are equal Compare returns 0 if Lhs string is
> less than rhs string it returns a negative value if the string
> is greater it returns a positive value (the strings were not equal
> yet just doing compare would then mean the statement would evaluate
> to the truth which is not what you would intend)
>
> Anyhow ill hush now :)
>
>
> Jeremy Allen
> [EMAIL PROTECTED]
> Insert Quarter Here ---->[ ]<----
>
> -----Original Message-----
> From: Ricq Pattay [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 31, 2000 10:28 AM
> To: [EMAIL PROTECTED]
> Subject: YAFLQ (Yet Another "Fine" Locking Question)
>
>
> If I have references to session variables that are nested, do
> I need to lock
> each reference separately or can I wrap the whole thing in one
> lock?
>
> e.g.,
>
> <cflock scope="session" timeout="30" type="exclusive">
> <cfif #session.susertype# is not "admin">
> <cfquery name="get_message" datasource=#variable.ds#>
> select message_text
> from vcross.messages
> where
> <cfif #session.susertype# is "student"> [LOCK HERE?]
> message_type = 'student'
> </cfif>
> <cfif #session.susertype# is "faculty"> [LOCK HERE?]
> message_type = 'faculty'
> </cfif>
> </cfquery>
>
> <cfquery name="get_specific_message" datasource=#variable.ds#>
> select message_text
> from vcross.messages
> where message_type = 'specific'
> and user_id = #session.suser_id# [LOCK HERE?]
> </cfquery>
> </cfif>
> </cflock>
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
Comment: Please use PGP!!!
iQA/AwUBOa6boQraVoMWBwRBEQLUqwCg/C38wHdZM5ipmloK4CsJk/c8hRgAoOnf
eIzp85RKBTr/BcJ58Pnr1nT1
=yUbM
-----END PGP SIGNATURE-----
----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.