Acess variable that was set by thread

Emanuele Torre torreemanuele6 at gmail.com
Mon Aug 8 02:16:49 UTC 2022


On Monday, 8 August 2022 at 01:36:45 UTC, vc wrote:
> Hello, i have the following code, the flora contains a boolean 
> zeus
> in the DerivedThread the boolean zeus was set to true; but when 
> i'm trying to access it
> outside the thread in main it returns me false; any thoughts ?
>
> import flora;
>
> class DerivedThread : Thread
> {
>     this()
>     {
>         super(&run);
>     }
>
> private:
>     void run()
>     {
>         // Derived thread running.
>         zeus = true;
>
>         while(true)
>         {
>
>         }
>
>     }
> }
>
>
>
>
> void main()
> {
>
>     auto derived = new DerivedThread().start();
>
>     writeln(zeus);
>
> }

When `writeln(zeus)` runs, `zeus = true` probably was not 
evaluated yet.


More information about the Digitalmars-d-learn mailing list