shared - i need it to be useful

Dominikus Dittes Scherkl dominikus.scherkl at continental-corporation.com
Tue Oct 16 11:04:44 UTC 2018


On Tuesday, 16 October 2018 at 10:15:51 UTC, Timon Gehr wrote:
> On 15.10.2018 20:46, Manu wrote:
>> 
>> Assuming the rules above: "can't read or write to members", 
>> and the
>> understanding that `shared` methods are expected to have 
>> threadsafe
>> implementations (because that's the whole point), what are the 
>> risks
>> from allowing T* -> shared(T)* conversion?
>> 
>
> Unshared becomes useless, and in turn, shared becomes useless.
why is unshared useless?
Unshared means you can read an write to it.
If you give it to a function that expect something shared,
the function you had given it to can't read or write it, so it
can't do any harm.
Of course it can handle it threadsave, but as it is local,
that is only overhead - reading or changing the value can't do
any harm either. I like the idea.

> But useless, because there is no way to ensure thread safety of 
> reads and writes if only one party to the shared state knows 
> about the sharing.
Of course there is. Giving an unshared value to a function that
even can handle shared values may create some overhead, but is
indeed threadsave.





More information about the Digitalmars-d mailing list