Assuming you had some additional logic in your conditional check, like this:
listener (pseudo-code): function addToCart(product) { if (not structKeyExists(session,"cart")) session.cart = createObject("component","cart"); session.cart.addProduct(product); else session.cart.addProduct(product); // should this be locked? }
First off, that's the same logic I had except you now have extra code! The following does exactly the same:
listener (pseudo-code):
function addToCart(product) {
if (not structKeyExists(session,"cart"))
session.cart = createObject("component","cart");
session.cart.addProduct(product);
}Don't you have to lock the single call to "session.cart.addProduct()"?
Answer: unlikely but it depends...
It's in the session scope, and it seems to me that another thread could
possibly be reading or writing to this via the listener, so shouldn't it
be in an exclusive lock?
Only if the *same* user can make multiple simultaneous requests. That's unlikely. If your site uses frames (or it's an RIA) it is theoretically possible that a user *might* be able to initiate two simultaneous requests that *might* cause a problem.
Remember that the session scope is unique to each user.
And then shouldn't other reads of the cart (ie "session.cart.getCart()") have readonly locks?
Again, unlikely but it depends... If a single user can initiate sufficient simultaneous requests that multi-threading on their own session scope is possible, then you might need to be more aggressive about locking.
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive." -- Margaret Atwood
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
