Concurrency Confusion

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 7 22:14:18 PDT 2015


On Saturday, 8 August 2015 at 00:39:57 UTC, 岩倉 澪 wrote:
> Found the answer to this :) 
> http://forum.dlang.org/post/mailman.1706.1340318206.24740.digitalmars-d-learn@puremagic.com
>
> I send the results from my worker thread with assumeUnique, and 
> then simply cast away immutable in the receiving thread like so:
>
> (in module scope)
>     Bar[] baz;
>
> (in application loop)
>     import std.array
>     if(baz.empty)
>     {
>         import std.concurrency, std.datetime;
>         receiveTimeout(0.msecs,
>                 (immutable Bar[] bar){ baz = cast(Bar[])bar; });
>     }

I'm not completely sure that it's bad in this case, but you 
really shouldn't be casting away immutable. It's undefined 
behaviour in D.


More information about the Digitalmars-d-learn mailing list