Pointer across threads

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 4 08:35:42 PST 2014


On Tuesday, 4 November 2014 at 16:07:11 UTC, thedeemon wrote:
> 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.

That's what I was thinking too.


More information about the Digitalmars-d-learn mailing list