On Sunday, 10 April 2022 at 23:19:47 UTC, rikki cattermole wrote:
immutable isn't tied to lifetime semantics.
It only says that this memory will never be modified by anyone
during its lifetime.
This is clearly where I am misunderstanding. In my mind immutable
data means the data will not change and neither will the result
of reading that data, ever.
I don't get how you can have thread safety guarantees based on
immutable if reading that data in a thread suddenly becomes
undefined behaviour and could return anything. That isn't
immutable then. Once instantiated immutable data persists for the
remainder of the program. You may not have access if the variable
goes out of scope, but if you do it will always be there and
always return the same value when you read from memory.
Thanks for replying, I am not trying to be argumentative here,
just stating what I thought it meant and why I am confused. I'll
be doing some more reading of the D spec to better understand
immutability.
Cheers,
Norm