Nice to @Share?
Zdenek Tronicek
tronicek at fit.cvut.cz
Mon Feb 22 13:07:26 PST 2010
Joshua Bloch napsal(a):
> There are several reasons that I believe this not a good idea:
>
> (1) For fields (instance or static) this annotation is not required today
> (in anonymouns class instance creation expressions), and I believe that
> programmers are likely to see it as an added annoyance (like the current
> situation with final variables).
I think the annotation is only for local variables. As far as I know, in
the BGGA prototype it is not used for fields.
> (2) For local variables, I see it as too much magic:
>
> @Shared int i;
>
> has a totally different implementation from:
>
> int i;
>
> The latter creates a "container object" on the heap, the former doesn't.
> The
> semantics (in particular, the lifetime) and the performance are likely to
> differ significantly.
In the BGGA prototype, the annotation was meant as confirmation "I am
aware that this variable may be shared between threads". It does not
change the semantics because the variable can be captured even if it does
not have this annotation. In such case, the compiler emitted warning that
the captured variable is not annotated.
Z.
--
Zdenek Tronicek
FIT CTU in Prague
> (3) I believe it's an abuse of annotations. Some may liken it to
> @Override,
> but I believe this is specious. The @Override annotation merely expresses
> a
> compile-time assertion that the compiler is able to verify. The proposed
> @Shared annotation changes the semantics of the language.
>
> (4) If, in spite of all the above, it is the consesnsus that such an
> annotation is still a good idea, I believe the name @Shared could hardly
> be
> more misleading. In practical terms, it means "this variable must *not* be
> shared (without additional synchronization)." It would typically be used
> when the programmer could assert that the variable in question would never
> be sharead among multiple threads.
More information about the lambda-dev
mailing list