Nice to @Share?

Neal Gafter neal at gafter.com
Tue Feb 23 12:06:29 PST 2010


On Tue, Feb 23, 2010 at 11:51 AM, Doug Lea <dl at cs.oswego.edu> wrote:
> One cannot define a processor- or language-level memory
> model without reference to a category of variables that are
> intrinsically local to a processor/thread.

Why not?  It seems to me that widening the scope of the description of
"shared variables" (17.4.1) to include all variables - even those that
are not actually shared between threads - gives precisely the correct
semantics: if the variable is only used in one thread, then references
to it are intra-thread actions and therefore don't cause conflicts
(17.4.2); on the other hand if the variable is final (e.g. a local
variable used in an anonymous class) then the guarantees of "final
variable semantics" (17.5) would apply. Moreover, this simplifies the
specification, because the distinction need no longer be made. And in
the process of simplifying it, the specification goes from being
incorrect and incomplete (for the case of locals used in anonymous
classes) to correct and more complete.

> Of course, the absolute knowledge that a local is in fact
> thread-private is critical in implementing many concurrent
> algorithms. It is frightening to contemplate how to
> program  without this.

None of those concurrent algorithms would be undermined in any way by
allowing lambdas, or anonymous inner classes, to share local variables
from enclosing scopes.


More information about the lambda-dev mailing list