shared - i need it to be useful
Timon Gehr
timon.gehr at gmx.ch
Wed Oct 17 14:18:46 UTC 2018
On 17.10.2018 15:40, Steven Schveighoffer wrote:
> On 10/17/18 8:02 AM, Timon Gehr wrote:
>> Now, if a class has only shared members, that is another story. In
>> this case, all references should implicitly convert to shared. There's
>> a DIP I meant to write about this. (For all qualifiers, not just shared).
>
> When you say "shared members", you mean all the data is shared too or
> just the methods are shared?
>
> If not the data, D has a problem with encapsulation. Not only all the
> methods on the class must be shared, but ALL code in the entire module
> must be marked as using a shared class instance. Otherwise, other
> functions could modify the private data without using the proper synch
> mechanisms.
>
> We are better off requiring the cast, or enforcing that one must use a
> shared object to begin with.
>
> I think any sometimes-shared object is in any case going to benefit from
> parallel implementations for when the thing is unshared.
>
> -Steve
The specific proposal was that, for example, if a class is defined like
this:
shared class C{
// ...
}
then shared(C) and C are implicitly convertible to each other. The
change is not fully backwards-compatible, because right now, this
annotation just makes all members (data and methods) shared, but child
classes may introduce unshared members.
More information about the Digitalmars-d
mailing list