On 03/05/2011 19:06, Andrej Mitrovic wrote:
I'm trying to figure out how to use coroutines in D.

First, I think I've run into some kind of bug. I've followed this C++ example: 
http://www.subatomicglue.com/secret/coro/readme.html, and came up with this:

I'm not entirely sure what it is you want to be able to do (I'm rather tired and didn't want to read through the whole example, I'll take another look tomorrow unless someone else beats me to it), but from what I can gather you want to pass values to the fiber between calling and yielding?

The way to do this is to derive your fiber rather than composing it:

class Derived : Fiber
{
    size_t arg;
    this()
    {
        super(&run);
    }
    void func()
    {
        writefln("val: %s", arg);
        Fiber.yield();
        writefln("val: %s", arg);
    }
}

auto fiber = new Derived;
fiber.arg = 6;
fiber.call();
fiber.arg = 7;
fiber.call();

You have, however, encountered a bug - Fiber should not accept a function with parameters, you should file a bug report for this.

Hope this helps.

--
Robert
http://octarineparrot.com/

Reply via email to