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

Imperatorn johan_forsberg_86 at hotmail.com
Sun Nov 14 17:42:18 UTC 2021


On Sunday, 14 November 2021 at 16:55:24 UTC, Alexey wrote:
> 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();
> }
> ```

Try task(&threadFunc) instead of task!(&threadFunc)


More information about the Digitalmars-d-learn mailing list