discreteLock

For questions and postings not covered by the other forums
User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

discreteLock

Postby ghosttie » Sat Nov 03, 2012 3:02 am

When would you not want to use discreteLock on foreach?
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

murray
Posts: 144
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: discreteLock

Postby murray » Sat Nov 03, 2012 2:48 pm

When would you not want to use discreteLock on foreach?
... in cases where you want to ensure that the collection you are iterating is not changed by other processes.
You may be wanting to add up a total or count a number of objects, without concurrent processes adding or deleting objects during the iteration. It depends on your requirements.
I remember someone asking the related question "why does foreach always lock the collection for the entire iteration?" in a Jade training course many years back (version 5). The answer from the Jade trainer was to the effect of: "why wouldn't you want it that way?" and advocated the requirement for an invariant collection.
Obviously there are various cases, so use what's best in each case.
Murray (N.Z.)

JohnP
Posts: 73
Joined: Mon Sep 28, 2009 8:41 am
Location: Christchurch

Re: discreteLock

Postby JohnP » Mon Nov 05, 2012 9:16 am

If you are quickly iterating a large number of entries through the collection and there is no contention with updaters, it can be quicker without the discreteLock, since the collection lock is obtained only once. Normally the difference would be small, but if everything is in the node cache, the amount of time doing locks could become noticeable.

User avatar
suzuki1100
Posts: 29
Joined: Tue Nov 24, 2009 12:00 pm
Location: Auckland

Re: discreteLock

Postby suzuki1100 » Mon Nov 05, 2012 1:43 pm

Where the collection poses no issues with updates or locking contention.
i.e. its a transient collection available only to the current process


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 35 guests