"Christopher Wright" <[email protected]> wrote in message
news:[email protected]...
Lionello Lunesu wrote:
I like shared/const/immutable as much as the next guy, but there are now
2x2x3=12 ways to decorate a variable. Furthermore, by either declaring
the variable globally or locally (stack), we end up with 24 possible
declaration. See the code at the end of this post.
The decision to make a variable a static class or module member is
independent of whether to make it shared or not.
You're right, of course. I realize now that "static" is a storage class
(when used locally) not a type modifier.
Shared and const-level have to do with controlling access to the variable.
An immutable variable does not need to be declared shared.
So, immutable implies shared.
Shared const is for publish-subscribe sort of deals.
You mean one thread can change the value, but for another thread it's
constant? I can see how it would be useful using reference types, but I
don't understand how it would work with value types..
Shared mutable is for cooperative writing to the variable.
This one I understood :)
The point of a shared local variable is to pass it to another thread or
set of threads, which will then be able to mutate it without trouble.
As before, how can an int (value type) on the stack ever be shared with
another thread? It would always have to be copied... Can you give me an
example please?
Thanks,
L.