Pointer across threads

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 4 04:49:27 PST 2014


On Tuesday, 4 November 2014 at 12:47:11 UTC, Chris wrote:
> The following
>
> struct DATA {
>  short* data;
>  size_t len;
> }
>
> // data and len are provided by a C function
> // ...
> auto data = mymodule.getSpeechData();
> // cast to immutable, because of concurrency
> immutable short* tmp = cast(immutable)(data.data);
> auto proc = spawn(&processData, thisTid);
> send(processData, tmp, data.len);
>
> However, processData never receives "tmp". Is this because tmp 
> and data.data are still pointing to the same address? If this 
> is the case, why doesn't the compiler warn me? Or is it 
> something else (pointer not visible across threads?).
>
> Is there a work around? (I wanted to avoid having to convert 
> short* to short[] and .idup it.)

Sorry, it should read

send(proc, tmp, data.len);


More information about the Digitalmars-d-learn mailing list