Parallel-safe lambdas

Rémi Forax forax at univ-mlv.fr
Thu Feb 11 03:44:50 PST 2010


Le 11/02/2010 12:11, Mark Thornton a écrit :
> Rémi Forax wrote:
>> Mark, I don't think we need to distinguish between restricted
>> and unrestricted closure.
>> I prefer the idea to avoid shared states to let the implementation
>> choose if the code has to be run parallel or not.
>
> I think that is the restriction (no shared state) to which Stephen and 
> Olivier are objecting. In fact I think they are saying that shared 
> state is so important to their view of lambdas that they would prefer 
> to discard the parallel use of lambdas.
>
> Mark
>

I don't think we can come with a set of rules that doesn't
allow to mutate something.
By example, because there is no way in Java to know is a method is pure 
or not
and because you can't disable all method calls,
you can always mutate an objects using a method call.

// no mutation
sort(array, #(String s1, String s2) (s1.compareIgnoreCase(s2)));

// mutations
final Collection<String> c = ...
forEach(array, #(String s) {
    c.add(s);
});

Perhaps the best option is to maintain the current status quo,
local variable should be final, fields can be mutated.

lambda is already a restricted form of anonymous class.
A lambda doesn't define a class, unlike anonymous class,
so mutating something is less easy.

Rémi


More information about the lambda-dev mailing list