thread phobos and creating threads

Marcin dupek at gmail.com
Sat Sep 8 17:59:16 UTC 2018


https://run.dlang.io/is/PQkOfF

How to make it work?
void main()
{
     import core.stdc.math : sin;
     import core.thread;
     import std.stdio : write, writeln, writef, writefln;

     class DerivedThread : Thread
     {
         double d;
         this()
         {
             super(&run);
         }

         this(double a)
         {
             super(&run);
             this.d = sin(a);
             writeln(d);
             this.getD();
         }

     private:
         void setD(double d)
         {
             this.d = d;
         }

         double getD()
         {
             writeln(d);
             return d;
         }

         void run()
         {
             // Derived thread running.
         }
     }

     // create and start instances of each type
     auto derived = new DerivedThread(22).start().setD(11).getD();

}


More information about the Digitalmars-d-learn mailing list