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

Alexey animuspexus at protonmail.com
Sun Nov 14 12:01:36 UTC 2021


/home/animuspexus/dlang/d_v2.098.0/dmd/generated/linux/release/64/../../../../../phobos/std/parallelism.d(436): Error: need `this` for `threadFunc` of type `void()`
./t.d(22): Error: template instance 
`std.parallelism.Task!(threadFunc)` error instantiating


thou documentation says `a function (or delegate or other 
callable)`

```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