Shared

Dominikus Dittes Scherkl dominikus at scherkl.de
Thu May 16 10:35:52 UTC 2019


On Wednesday, 15 May 2019 at 09:33:19 UTC, Jonathan M Davis wrote:
> On Wednesday, May 15, 2019 12:59:00 AM MDT Dominikus Dittes 
> Scherkl via Digitalmars-d wrote:
>> No, it can't. Disjunct means: It cannot be called unless all 
>> of the given variables are free (not locked by any other 
>> mutex).
>
> So, you're proposing that something in the runtime keeps track 
> of which variables are currently associated with a locked mutex 
> in order to guarantee that no other lock block is able to 
> access any of those variables at the same time? That would 
> probably require adding a global lock used by the runtime when 
> any code enters or exists a lock block. I'd be _very_ surprised 
> if anything like that were deemed acceptable for D.
Ok, that can be a problem. But yes, this is what I suggest.
But why the resistence? Nobody is forced to use mutexes, and if 
you don't that part of the runtime could (should!) be eliminated 
from the program.

> And it still doesn't solve the problem of other references 
> referring to any part of the objects referred to by those 
> variables existing and potentially being used elsewhere. If you 
> had
>
> lock(mutex, var1)
> {
> }
>
> and elsewhere
>
> lock(mutex, var2)
> {
> }
>
> when var1 and var2 were references to the same object
Forbidden. See last post.

> or when var2 referred to a piece of data inside of var1,
This would also be impossible. shared vars are no references.

> If you only had one mutex for the entire program, and casting 
> away shared were illegal, then something like this could 
> probably work,
Thank you, but why this restriction? There can be as many mutexes 
as you like. The runtime has only to ensure that any running 
locked block doesn't modify any of the vars in the other running 
locked blocks.



More information about the Digitalmars-d mailing list