Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Fiber.yield acting strange in libtango-ldc-daily-dev (.99.8+20090829)

Moderators: kris

Posted: 09/01/09 20:46:05

This issue is sort of halfway between a possible bug in the Tango fiber library and my own inexperience in D.

I'm trying to use Fibers to implement a flow-based programming environment similar to the Kamaelia/Axon Python project. Basically Axon implements a cooperative multitasking component system where continuation components communicate with each other via mailboxes.

This should be moderately straightforward in D/Tango/Fibers. I've written the microprocess, scheduler, component and mailbox classes. For the most part these work just fine and have been tested outside of Fibers.

What has me stumped is the following: The Component class inherits from Fiber. Each component sits in a wait forever loop, read from its inbox(s), does some computation, writes to its outbox(s) and then yields. When components read from an empty inbox (inbox.read()) I want the component to yield.

The only problem is that 'read' is an inbox method and inbox is not a Fiber.

In other words, I don't know if the following is allowed

class Inbox : LinkedList?!(T) { ...

T read() {

while (!this.size) {

owner.runState = STATE.WAIT; Fiber.yield();

} return this.removeHead();

}

... }

class Component : Fiber {

Inbox!(int) myInbox; int r;

...

this() {

super(&run); myInbox = new Inbox!(int);

}

...

void run() {

while (true) {

r = myInbox.read(); crunch(r); outbox.send(r); Fiber.yield();

}

... }

Currently this design is only working intermittently. Sometimes it crashes in a segmentation violation. Sometimes it goes into runaway recursion. Once in a while it works for about 10 iterations.

As I said, I'm not sure if this is my error for calling Fiber.yield() in a non-Fiber object (even though its the same thread), or it's a bug in the Fiber system.

Any help greatly appreciated.

Thanks,

J Burnes

There are no responses to display.