Functions outside the CFC that access the variable scope will not have thread safety issues when 2 requests run the code, but if you use cfthread or other parallel functions, you may still have problems with the variable variable scope, and this can cause conditions race. Often this error can occur with a variable that you use a lot, for example, in a for loop, the variable "i".
for (i = 1; i <10; i ++) {t = arr [I]; }
But then another function does this during the first run:
for (i = 1; i <20; i ++) {t = arr [I]; }
The variable "i" must become a local variable to make it thread safe. You do not want the first cycle to go above 10 by mistake, and it is difficult to debug many times. I had to fix a ton of "i" variables and others to make my functions thread safe everywhere when I started caching objects and using cfthread more widely.
You can also avoid the need for locking by never changing existing objects. Instead, you can work on copies. This makes the data "unchanged." CFML does not have official support for creating immutable objects more efficiently, but you can make copies easily. http://en.wikipedia.org/wiki/Immutable_object
A simple example of securely changing the flow for a variable application area:
var temp=structnew(); // build complete object temp.myValue=true; // set complete object to application scope variable application.myObject=temp;
Writing to any shared object is often dangerous, because variables can be undefined or partially constructed. I always create a complete object and set it to a shared variable at the end, as in the example above. This facilitates thread safety if it is not too expensive to recreate data. The scope of variables in CFC is similar to a member variable in other languages. If you modify data in shared objects, you could use CFLOCK if you cannot make copies.
Some confusion in the field of cold resistance is associated with common areas in coldfusion 5 and previously less reliable. They had serious thread safety issues that could lead to data corruption or crashes. Under certain conditions, two streams could write to the same memory at the same time, if you did not block them correctly. Modern CFML engines can write to structural keys without the possibility of corruption / failure. You simply cannot be sure which data will actually end up as value without some consideration of thread safety now, but it will usually not be corrupted unless you deal with object types other than cfml, such as CFX, Java, and others The thread's security error can still lead to an infinite loop that can hang up the request until it expires, but it should not crash if it does not run out of memory.