Want reasonable reference counting? Disable automatic sharing of immutable
Stanislav Blinov
stanislav.blinov at gmail.com
Sun Nov 14 01:15:06 UTC 2021
On Sunday, 14 November 2021 at 00:17:29 UTC, Elronnd wrote:
> On Saturday, 13 November 2021 at 23:08:01 UTC, Stanislav Blinov
> wrote:
>> Read `a`, call pure function, read `a`. Where is it possible
>> for `a` to mutate, after first read and before second read?
>> Can't be the pure function, it's pure and cant mutate `a`. So
>> where is it possible for `a` to mutate?
>
> auto x = new int;
> assert(a < 5);
> auto y = new int;
> assert(a < 5);
> *x += *y;
>
> Would you begrudge the compiler the ability to remove the
> second assert? Because there is the _exact_ same problem there.
So long as collection can call any destructors indiscriminately -
yes, I would. Because with current runtime and GC spec `a` might
mutate in either call to `new`. Even in both.
> Actually, forget allocation. A signal can occur at _any_ time,
> and its handler can change globals.
Indeed, forget allocation, given that I'm talking about
collection. But anyway, so what? What do signals have to do with
`new` pretending to be pure when it calls destructors that aren't?
>> Can't be another thread, `a` is a thread-local int.
>
> You can share pointers to thread-local objects.
Indeed you can. How does that apply here?
More information about the Digitalmars-d
mailing list