> -----Original Message-----
> From: Tony Hicks [mailto:[EMAIL PROTECTED]
> Sent: Friday, December 31, 2004 2:03 PM
> To: CF-Talk
> Subject: Re: Well - I feel like an idiot.
> 
> Either I like to stick my foot in my mouth, or I'm feeling gutsy but I
> was looking at livedocs for application variables on another thing and
> it did say for data integrity you SHOULD lock.
> 
> http://livedocs.macromedia.com/coldfusion/6/Developing_ColdFusion_MX_Appli
> cations_with_CFML/sharedVars6.htm
> 
> http://livedocs.macromedia.com/coldfusion/6/Developing_ColdFusion_MX_Appli
> cations_with_CFML/sharedVars8.htm#1154837

Yeah - but they're wrong.  ;^)

As I said - this is one of the biggest, most confused topics in CF.

The way I like to say it is that if you don't understand locking then ALWAYS
lock.  You'll lose some performance, but won't corrupt your app.

In the Pre-MX days failure to lock could mean server death however - the
internal structures used to store memory resident variables were not,
themselves, thread safe.  Failure to lock would often cause server memory
corruption.

This could even happen (because of those internal structures) that a simple
read could happen before a write was finished leaving the read with
corrupted data.

In MX the internal structures are thread safe themselves.  However that
doesn't mean you can't screw things up.  The biggest potential problems is
"race conditions" - conditions were two requests accessing the same
variables would cause confusion or incorrect data.

To prevent race conditions you lock your code - and if you don't know if
you'll have a race condition then you should probably lock to be safe.

Also you don't have to worry as much about reads - the read will always work
(even if it doesn't give you the data that you think it should).

In MX not locking will just cause application-level problems, not
server-level problems.  If you understand the issues at play you can safely
optimize your code by not locking in many cases.

But the core advice of "always lock" is definitely the safer option.

Jim Davis



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:189077
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to