Want reasonable reference counting? Disable automatic sharing of immutable

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Nov 15 13:08:52 UTC 2021


On Monday, 15 November 2021 at 11:58:56 UTC, Stefan Koch wrote:
> And const doesn't provide any additional grantees an optimizer 
> could use directly.
> It's a feature to prevent misuse of an API only.
>
> I have personal experience which show that as soon as multiple 
> threads involved const does more harm than good because it only 
> allows you to reason about _your access rights_ you cannot 
> infer anything about anyone else.

I wonder if it would be interesting to have a const reference 
that guarantees that the underlying data-structure does not 
change as long as the reference or any copies of it are live? I 
guess that could be another reason for adding tracking of 
borrowing.

Use case: you obtain a record from a database thread in a 
transaction, when the transaction is ending the database gets to 
mutate the record again.

You add the constraint that only @trusted functions are allowed 
to create such const-references.




More information about the Digitalmars-d mailing list