Very limited shared promotion

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jun 18 21:20:13 UTC 2019


On Tuesday, June 18, 2019 2:57:20 PM MDT Ola Fosheim Grostad via 
Digitalmars-d wrote:
> On Tuesday, 18 June 2019 at 09:01:47 UTC, Manu wrote:
> > The access function returns a scoped lock object with a ref
> > count. You may take many read ref's, a write access has a
> > maximum of 1 ref. You may not take a read and a write lock at
> > the same time.
>
> But, you could take the address of an attribute or object and
> retain it?  So this is only by convention? Or is the type system
> able to ensure this?

scope only makes guarantees for @safe code. As soon as anything is @system
or @trusted, all bets are off. So, _if_ all of the code involved is @safe,
then the address of the scope object couldn't be taken, and no references to
the scope object could escape. However, all that's required is a piece of
@trusted code with access to the scope object, and all protections go out
the window. At that point, it's up to the programmer to ensure that the code
doesn't violate the guarantees that the compiler expects @safe code to make
- including whatever guarantess go along with scope in @safe code.

- Jonathan M Davis





More information about the Digitalmars-d mailing list