shared - i need it to be useful

Neia Neutuladh neia at ikeran.org
Sun Oct 21 22:12:18 UTC 2018


On Sun, 21 Oct 2018 12:04:16 -0700, Manu wrote:
> On Sun, Oct 21, 2018 at 12:00 PM Timon Gehr via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> Note that there may well be a good way to get the good properties of MP
>> without breaking the type system, but MP itself is not good because it
>> breaks @safe.
> 
> Show me. Nobody has been able to show that yet. I'd really like to know
> this.

If we only used your proposal and only used @safe code, we wouldn't have 
any data races, but that's only because we wouldn't have any shared data. 
We'd have shared *variables*, but they would not contain any data we could 
read or alter, and that's pretty much useless.

To use your proposal, we need to cast data back from shared to unshared. 
When it's unshared, we need to make sure that exactly one thread has a 
reference to that data as unshared. And @safe *should* help us with that. 
Currently, it helps because casting unshared to shared is not @safe, 
because it makes it trivial to get multiple threads with unshared 
references to the same data. And that's when you're using shared as 
expected rather than doing something weird.


More information about the Digitalmars-d mailing list