shared - no read/write access

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Mar 31 07:06:12 UTC 2019


On Wednesday, March 20, 2019 7:25:01 AM MDT Stefan Koch via Digitalmars-d 
wrote:
> On Tuesday, 19 March 2019 at 21:20:58 UTC, Kagamin wrote:
> > On Tuesday, 19 March 2019 at 20:08:37 UTC, Manu wrote:
> >> Last time we talked about shared, I think we all agreed on one
> >> thing; shared should hot have read/write access to data
> >> members.
> >>
> >> Does anyone know how to implement this? I would really like to
> >> try some important experiments with shared if it worked.
> >
> > shared qualifier provides a guarantee that thread local data is
> > thread local, it doesn't provide safety for concurrency, not
> > supposed to, because it's not realistically feasible at such
> > low level, and attempts to do it like yours only add noise,
> > complicate reasoning and make errors only more likely. Normally
> > it's unshared data that should have a qualifier, because that's
> > actually a feature being provided, but because it would be a
> > nuisance, the opposite was done.
>
> In it's current form the `shared` qualifier is not improving the
> thread-safety
> of D code. Manus proposal does improve thread-safety.
> I am strongly in favor for considering it seriously.
>
> Being conservative and disallowing all access is by far the most
> sensible handling
> if safety is a concern.

shared already prevents some operations that the compiler can't guarantee
are thread-safe (e.g. IIRC, ++i on built-in types is disallowed). The
problem is that it doesn't prevent all of them, and it can't work properly
unless it does, because otherwise it can't make any guarantees about
thread-safety, which is one of the main reasons that shared exists. As with
@safe, the protections on shared have been added piecemeal over time rather
than getting it all figured out up front like ideally would have happened.

- Jonathan M Davis





More information about the Digitalmars-d mailing list