[dmd-concurrency] is shared going to be a type modifier?

Steve Schveighoffer schveiguy at yahoo.com
Thu Jan 7 11:30:25 PST 2010


----- Original Message ----

> From: Andrei Alexandrescu <andrei at erdani.com>
> Yes, shared is a type qualifier. For the most part it behaves like immutable. 
> Note that you can define an immutable member of an otherwise mutable type.
> 

Right, but this to me makes sense -- I want to define something that is always immutable.  A piece of data becomes immutable the second you declare it is.

But when I mark a class member shared, it does not truly become shared by declaring it that way -- allocating an instance of such a class does not make its shared members available to other threads.  Compare that to a global, which is immediately shared.  I think this is going to have to be really explained well.  As a member storage class, shared really should be called "shareable".

Despite that, I think I get it.  The address to a shared member could be passed to other threads, even though the full object is not, is that correct?  I can see use cases for that.  From that point of view, it's not so important that you are declaring something is partially shared, but that it's partially thread-local.  That is, something that isn't marked shared can be used in a shared or unshared capacity, but something that is marked even partially shared you only ever want to use in a shared manner -- you'd never use such a class as a thread-local-only object.

OTOH, it's good to hear shared is going to remain a type modifier, because I need that in order to distinguish shared and non-shared array appends.

-Steve



      


More information about the dmd-concurrency mailing list