This is a follow-up to
I get this error if I use tvanek's code with a NAME attribute:
Attribute set validation error in tag CFLOCK
The tag has an invalid attribute combination: the most likely attribute combinations are
Required attributes: 'SCOPE,TIMEOUT'. Optional attributes: 'THROWONTIMEOUT,TYPE'.
Required attributes: 'TIMEOUT'. Optional attributes: 'NAME,THROWONTIMEOUT,TYPE'
Other possible combination is
Here's the code:
<cfset session.fighter = 1>
<CFLOCK NAME="test_lock" TYPE="EXCLUSIVE" scope="SESSION" TIMEOUT="60">
<cfset foo = structDelete(session, "fighter")>
I've never used <CFLOCK> before, so I decided to read up on it. I've got the "Mastering ColdFusion" book by Arman Danesh (good book). He recommends to use the NAME attribute (page 479):
"Although [the NAME] attribute is not required, it is hightly recommended that you use it."
"If two CFLOCK tags share the same name, then only one tag can be accessed at a time. If you do not name them in this manner, you could run into read/write access problems.
For example, if application.test is set in one template, but no CFLOCK name is specified, ColdFusion will automatically generate a random name to lock the code. But say that in a second template someone is trying to read application.test and the lock around that code has no NAME attribute as well. ColdFusion will generate a unique name, but it will not be the same name that locks the write access to application.test in the girst template. So you could have one user writing to the variable and another user reading the variable at the same time. This can cause the server to hang, or incorrect data to be to the variable."
So, if it's so highly recommended to use the NAME attribute, how come I get this "invalid attribute combination" error? What's the use of locking and area of code using a randomly unique name? It'll still allows two clients access to the same data causing possible data corruption.
What's the proper syntax?