> 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.
Prior to MX, the ColdFusion server could become unstable if persistent scope variables were referenced outside of cflock tags on the given scope (or at least the variable). In some cases this resulted in a person seeing someone else's session information (or so I heard) but in most cases it merely resulted in general system instability and an eventual service/server restart. Obviously the more traffic was involved, the greater the likelyhood of instability as the instability itself was caused by variable accesses not being thread-safe and resulting in the underlying C++ architecture attempting to reference undefined variables, variables in the wrong state, the wrong variable, etc. This resulted in the "best practice" being to duplicate structures in and out of the persistent scopes in the Application.cfm and OnRequestEnd.cfm templates like this: <cflock scope="session"> <cfset request.session = duplicate(session)> </cflock> ------------- <cflock scope="session"> <cfset structappend(session,request.session,true)> </cflock> With MX and subsequent versions server instability is no longer a danger and cflock can be used purely to address race-conditions and to single-thread third-party tools which might not be thread-safe (an old COM object that's known to have this problem for instance). You can of course find lots of information about "race conditions" from Google. The long and the short of it is that if a process requires multiple steps which must occur in unison without being interrupted by another page request, a named cflock allows the process to be single-threaded so that subsequent requests to perform the task are queued. As an exmaple lets say you have a process which reads an xml file, modifies the xml and then writes it again. If two users attempt to simultaneously execute pages which modify the xml file in different ways, you could end up with one user's modifications overwriting the other user's modifications. <cffile action="read" file="#myfile#" variable="strXML"> <cfset xml = xmlParse(strXML)> .... change the xml ... <cffile action="write" file="#myFile#" variable="#toString(xml)#"> USER 1 > read file USER 1 > modify file USER 2 > read file USER 1 > write file USER 2 > modify file (since the file was read prior to the USER 1 write, the file being modified discludes the changes made by USER 1) USER 2 > write file (overwrites and loses the changes made by USER 1). To prevent this happening, you would simply place the above code in a named cflock, and since the file name is unique on the file system, it makes a perfect name for the lock: <cflock name="#myfile#" type="exclusive" timeout="10"> <cffile action="read" file="#myfile#" variable="strXML"> <cfset xml = xmlParse(strXML)> ... change the xml ... <cffile action="write" file="#myFile#" variable="#toString(xml)#"> </cflock> There's a lot of good info about cflock in general on Jim Davis site at http://www.depressedpress.com hth s. isaac dealey 954.522.6080 new epoch : isn't it time for a change? add features without fixtures with the onTap open source framework http://macromedia.breezecentral.com/p49777853/ http://www.sys-con.com/author/?id=4806 http://www.fusiontap.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:201028 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=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

