capturing (or not) mutable local variables

Steven Simpson ss at comp.lancs.ac.uk
Mon Nov 22 03:25:24 PST 2010


On 22/11/10 07:57, Howard Lovatt wrote:
> 2. As others have pointed out fields can be marked volatile and locals
> can't, which helps in making a lambda thread safe when writing to a
> field (and it would be hard to add volatile to a local).

Would it be so hard?  'volatile' is currently meaningless on a local
because it can only be accessed by one thread anyway, so it would be
safe to ignore it if not referenced from a closure/inner class (right?).

If it was referenced from a closure or inner class, how would it be made
mutable?  From what I've seen, the only proposals are to box it up in
some object, e.g. array of 1, or anonymous class.  Within that box, it
could be declared volatile.

Cheers!

-- 




More information about the lambda-dev mailing list