Shared

Dominikus Dittes Scherkl dominikus at scherkl.de
Tue May 14 12:22:20 UTC 2019


On Monday, 13 May 2019 at 16:20:30 UTC, Jonathan M Davis wrote:
> On Monday, May 13, 2019 9:52:02 AM MDT Dominikus Dittes Scherkl 
> via Digitalmars-d wrote:
>> On Saturday, 11 May 2019 at 15:24:19 UTC, Jonathan M Davis 
>> wrote:
>> > All that really would do is add a bit of extra syntax around 
>> > locking a mutex and casting away shared.
>>
>> No, it makes it possible to use mutex in safe functions 
>> without needing to cast and which the compiler CAN guarantee 
>> to really be safe.
>
> Actually, it doesn't. All you've done is lock a mutex and cast 
> away shared. There is no guarantee that that mutex is always 
> used when that object is accessed. There could easily be 
> another piece of code somewhere that casts away shared without 
> locking anything at the same time.
But that piece of code is system, which explicitly allows you to 
shoot into your foot. If you want to stay safe, don't do that.

> And even if this were the only mechanism for removing shared, 
> you could easily use it with the same object and a completely 
> different mutex in another piece of code
Yes, the lock block need a list of vars that it allows to be 
modified

lock(var1, var2, ...)
{
}

two mutexes can only be executed at parallel if their parameter 
set is disjunct.


> And even if the compiler could check that all uses of a 
> particular variable were locked with a mutex, that still 
> wouldn't be enough, because other references to the same data 
> could exist.
ok, so we need in addition that a reference to a shared var need 
not be lived beyond the end of the locked block or be immutable. 
Bad, but seems necessary.




More information about the Digitalmars-d mailing list