Pointer across threads
thedeemon via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 4 08:07:09 PST 2014
On Tuesday, 4 November 2014 at 14:36:19 UTC, Chris wrote:
> I'm still curious, though, how D handles this internally,
> because data.data is still mutable while the other reference to
> the same address (tmp) is not. What if I change data.data while
> the other thread is being executed?
"immutable" is part of the static type system, it's a label that
only exists and makes sense at compile time, for compiler and the
programmer. Casting a mutable data pointer to immutable data
pointer is a no-op, just a copy of pointer. Address stays the
same, data stays the same. So if you mutate the data it will lead
to "immutable" data being changed just because it's not really
immutable, you've just fooled yourself when doing the cast.
More information about the Digitalmars-d-learn
mailing list