Pointer across threads
Chris via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 4 07:05:48 PST 2014
On Tuesday, 4 November 2014 at 14:47:49 UTC, anonymous 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?
>
> Changing *data.data would be undefined behaviour. Don't do it.
> Once data is typed as immutable, it must not change anymore. By
> casting you're side-stepping the type system, so that you have
> to
> make sure of such things yourself.
Hm. I'm not planning to change data.data, of course, but I was
worried (and curious) about potential safety issues. I suppose I
could convert short* to short[] > idup it > pass a reference to
the C function (that expects short*). However, I want to avoid
this, because there shouldn't be any additional operations (it's
a (near) real time system).
More information about the Digitalmars-d-learn
mailing list