Burns, John D wrote: > I know there were some discussions on here recently about when you do > and don't need to use cflock and some discussion about changes on when > you needed to from 5 to 6.1. Can anyone give a quick recap of that or > point me to the archives on where I could find that discussion? I can't > seem to find it via the search. I'm looking for some facts and > reasoning behind why you do or don't need to use cflock in certain > situations. Thanks. > > John Burns > Certified Advanced ColdFusion MX Developer
And you wonder why I've never gotten my certification... ;) I'll recap for you. CF5 & below, you had to cflock every shared scope variable or your server would crash. Sometimes many times an hour (trust me). CFMX of course fixes that. Now you need to lock for race conditions. CFMX is multi-threaded, so two people can be doing the exact same thing at the exact same time. It's good in the way that your server can do a lot at once, but sometimes that's not safe. For instance, the generic example, an application-scoped hit counter. User A and user B hit a page at the same time, but A's thread goes through first. A's thread reads the variable, currently 100, and adds one to it, however, before it's set back into memory, user B reads it, it's 100. User A completes the process, setting the counter at 101. User B, having read it at 100, sets it to 101 as well. This race condition caused the hit counter to be off by 1. It seems unlikely, but believe me, these kinds of things can happen very easily, especially when you increase the amout of work you're doing with the shared scope. Looping, etc., will create issues with just 2 people using an application. Now here's a real life example. We have a login form. When you log in, we validate your credentials, erase previous session variables and set some new ones, then the request is forwarded to another page to set some session variables and output them. If you double-click the login button, 2 requests are sent to the server. The first thread is attempting to output your session variables while the first thread is deleting them for a fresh login. The server throws an undefined variable exception on the first thread, and thus, I get an email. After some creative locking, I've eliminated the error altogether, even though customers never saw it to begin with. I should blog this & refer it to people... ehh. -nathan strutz http://www.dopefly.com/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Find out how CFTicket can increase your company's customer support efficiency by 100% http://www.houseoffusion.com/banners/view.cfm?bannerid=49 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:201025 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

