Nice to @Share?
Neal Gafter
neal at gafter.com
Tue Feb 23 09:03:27 PST 2010
On Tue, Feb 23, 2010 at 3:17 AM, Alex Buckley <Alex.Buckley at sun.com> wrote:
> Consider also JLS3 17.4.1: "Local variables ... are never shared between
> threads and are unaffected by the memory model."
On second thought, that sentence appears to be a spec bug. Local
variables can indeed be shared between threads, though today that
requires the variable be final and used in an inner class. The memory
model doesn't say what the behavior should be (another bug), but I
expect section 17.5 should be generalized to talk about "final
variables" instead of just "final fields". Otherwise the JLS is
simply not correct today.
Your description of local variables being "stack allocated" does not
match the JLS description. According to the JLS, local variables are
allocated in the activation frame. That may be a stack, a heap, or
some combination of the two. There is no requirement regarding the
timing of deallocation of these frames.
More information about the lambda-dev
mailing list