capturing (or not) mutable local variables

Peter Levart peter.levart at marand.si
Mon Nov 22 04:38:27 PST 2010


On 11/22/10, Rémi Forax wrote:
> Using AtomicXXX is not a good idea too.
> 
> By example, if you want to sum a collection of integers using an atomic 
> variable,
> this means the volatile variable (inside the atomic class) will be updated
> for each element.
> 
> If you use a map/reduce pattern, you only need one synchronization point
> at the end of the calculation so the map/reduce code outperforms
> the solution with an atomic variable.

Or you can use Cliff Click's ConcurrentAutoTable from the http://sourceforge.net/projects/high-scale-lib/

Which is a single counter that automatically spreads the load (using hashing) to multiple independent counters and at each retrieval sums (reduces) them.

The style you take to solve a problem depends on the problem. map/reduce is suitable for batch processing while a single counter is more suitable if you want concurrent monitoring of dynamic counter.

Regards, Peter


More information about the lambda-dev mailing list