I am wondering how I do I pass a fiber to a thread?
The only way that I managed to do it was by casting to and from shared
.
auto fiber = new Fiber((){
});
auto t = spawn((){
auto fib = cast(Fiber)receiveOnly!(shared(Fiber));
writeln("fib");
fib.call();
});
send(t, cast(shared(Fiber))fiber);
But that doesn't seem right. I think I don't fully understand the implications of shared
.
I had to cast the fiber to shared because I wasn't allowed to send it to the thread without it. I had to cast it back to a fiber because I couldn't call Fiber.call
on a shared fiber.
What is the correct way of passing a Fiber
to a thread?