On Thursday, 15 October 2015 at 15:20:25 UTC, Steven
Schveighoffer wrote:
On 10/13/15 2:58 AM, Andrei Alexandrescu wrote:
https://github.com/D-Programming-Language/dmd/pull/5188
implements a
rule defined in TDPL: synchronized classes shall have no
public members.
When I first read this, I thought "how the hell will you use
this thing then?"
Then after reading through most of this thread, I realize you
mean public *field* members. Public *method* members are
allowed, right?
Yes. The idea is that with a synchronized class, all access to
the object must be via its member functions so that you can't
bypass the mutex that protects the object. Then, because the
compiler knows that nothing else can have direct access to the
class' member variables and that they're protected by a mutex
when inside of a member function, it's able to strip the outer
layer of shared from the member variables when you operate on
them. So, for basic cases at least, we don't have to cast away
shared to operate on shared data - though for more complicated
cases (e.g. stuff where stripping off the outer layer of shared
isn't enough), you'd still have to cast away shared (though at
least, it still encapsulates the shared data on some level in
that case).
- Jonathan M Davis