shared switch

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Oct 8 05:27:54 UTC 2023


On Saturday, 7 October 2023 at 09:26:09 UTC, Imperatorn wrote:
> Regarding shared, why is preview=nosharedaccess not the default?

because it break a bunch of stuff

> Instead it could have been preview=sharedaccess.
>
> I thought the point was that you want protection, otherwise you 
> would use __gshared?
>
> Input?

The idea is that access to shared variables is unsafe.
So in order to access them you need to do so through a @trusted 
interface that does the appropriate thing (atomics, locks, 
whatever).
To force you to use the correct interface, 
-preview=nosharedaccess forbids both reads and writes of shared 
variables (hence no access) and so (in the implementation) you 
must `cast()` (which is a safety violation), and so those 
functions must be @trusted to be used from @safe code.


More information about the Digitalmars-d mailing list