> i know why, but i dont know why!  Why won't CF just lock it all the time
> automatically

You can set up automatic read locking in CF Admin, though I *think* it gives
you less control on a line by line level if you need it =-/

>  who would want shared data with sessions when they can already use an
application variable for that.

They shouldn't as long as the data isn't dependant upon who is accessing it.
Application variables are application wide, meaning all users see the same
info.  Session variables are user speciffic, meaning each user can have some
different data, but it's still a shared memory variable.  They both exist
for a reason :)

> Also I dont understand nested
> lockings and how it works.  All I usually end up doing is putting a
Session
> lock around every session variable I see.  or if the session is used in a
> CFIF tag, i put the lock around that CFIF tag (not the closing CFIF tag).
> Or if there are a bunch of session variavles being read/written to, i put
a
> session lock over them.  heck, why not just surround the whole page with
one

This might be a 'broad' explanation of why this is bad, but here ya go:  If
you wrap a lock around a section of code, that code can become
single-threaded .. meaning that only one person can have access to that code
at one time.  If you wrap an entire page with a lock, then it potentially
can't be executed by more than 1 person at a time.  This can be a serious
performance issue, as I'm sure you can see.  That's why it's important only
to lock the section of code you absolutely need to.  I might be way off, but
that's just how I've always thought of it .. why lock more than you have to?

Say you have 10 Session variables and 9 are read from and one is written to.
A read lock will allow several people to read from that variable at once,
but prevents someone from writing to it until all the reads are done.
Exclusively locking a variable will not let anyone access the variable in
any way as long as there is one person accessing that variable.  I doesn't
make much sense to exclusively lock all 10 variables when you only have to
do one.  This might cause some serious performance hits if that page is at
all popular.

In the case where you have a bunch of Session variables that are being read
and written to all in a short period of time, you will have to use your best
judgement as to when to locks groups of code, or individual lines.  There is
a performance hit to grouping entire blocks of code in a lock, but there is
also one to making a lock, letting it go, and then recreating a new one
repetatively.

I've only made a very generalised explanation, and I'm probably not 100%
accurate in a few places, but you should get a basic answer to your
questions from it :)

Todd



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to