Want reasonable reference counting? Disable automatic sharing of immutable
Elronnd
elronnd at elronnd.net
Sun Nov 14 00:17:29 UTC 2021
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.
Actually, forget allocation. A signal can occur at _any_ time,
and its handler can change globals.
> Can't be another thread, `a` is a thread-local int.
You can share pointers to thread-local objects.
More information about the Digitalmars-d
mailing list