need `this` on trying to use class method with parallelism Task! or task!

Alexey animuspexus at protonmail.com
Sun Nov 14 16:55:24 UTC 2021


On Sunday, 14 November 2021 at 16:40:58 UTC, Andrey Zherikov 
wrote:
> Just do `auto t1 = task(&threadFunc)` in `threadCreator` then.


Error: value of `this` is not known at compile time

```D
import std.stdio;
import std.parallelism;

class TC
{
     void threadFunc()
     {
         import core.thread;
         import core.time;

         scope (exit)
             writeln("threadFunc done");

         core.thread.osthread.Thread.getThis.sleep(msecs(2000));
     }

     void threadCreator()
     {
         scope (exit)
             writeln("threadCreator done");

         auto t1 = task!(&threadFunc);
         t1.executeInNewThread();
     }
}

void main()
{
     scope (exit)
         writeln("main done");

     auto tc = new TC;
     tc.threadCreator();
}
```



More information about the Digitalmars-d-learn mailing list