Possible to pass a member function to spawn?

Sean Kelly sean at invisibleduck.org
Tue Feb 7 14:33:01 PST 2012


On Feb 6, 2012, at 1:38 PM, Oliver Puerto wrote:

> Hello,
> 
> I'm very new to D. Just started reading "The D programming language". I should read it from beginning to end before posting questions here. I know ... But I'm just too impatient. The issue seems not to be that simple, nevertheless. The code below compiles with Visual Studio.
> 
> I want to have something like my actor class that I can start running in it's own thread like in Scala or other languages that support actors. So at best, I would like to do something like this:
> 
>    MyActor myActor = new MyActor();
>    auto tid = spawn(&start, &myActor.run());

This should work:

void runActor(shared MyActor a) { (cast(MyActor)a)).run(); }
MyActor myActor = new MyActor();
auto tid = spawn(cast(shared MyActor) myActor, &runActor);


std.concurrency really should allow unique references to a non-shared type to be passed as well, using something similar to assumeUnique.


More information about the Digitalmars-d mailing list