shared attribute

japplegame japplegame at gmail.com
Sun May 13 05:35:14 PDT 2012


Very intresting. Next question. :)
Lets consider this example.
>import core.thread;
>import std.stdio;
>
>shared char[] s;
>char[] l = "shared text".dup;
>
>void main() {
>  Thread worker = new Thread(&workerFunc);
>  worker.start();
>  Thread.sleep(dur!"seconds"(5)); // after this point worker 
> thread and its
>                                  // local storage most likely 
> destroyed
>  s[2] = 'd';                     // undefined behaviour?
>}
>
>void workerFunc() {
>   s = cast(shared)l;
>}







More information about the Digitalmars-d-learn mailing list