capturing (or not) mutable local variables
Rémi Forax
forax at univ-mlv.fr
Mon Nov 22 00:17:18 PST 2010
Le 22/11/2010 08:57, Howard Lovatt a écrit :
[...]
> Tell people that if they want mutable state they should use AtomicXXX
> to guarantee thread safety. It is a pity that Java didn't make
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.
> everything immutable in 95 and that you have to mark stuff as mutable
> using AtomicXXX (however this is looking back 15 years and it is very
> easy to spot mistakes in hindsight and the fact is that Java was much
> better than anything else in 95 and did provide state of the art
> parallel constructs for 95).
>
> Cheers,
>
> -- Howard.
Rémi
More information about the lambda-dev
mailing list