First, I tried following Coroutine code with Fiber, but caused segmentation fault.
-----
Fiber child, parent;
child = new Fiber(delegate() {
writeln("before call parent");
parent.call(); // invoke parent fiber
writeln("after call parent");
});
parent = new Fiber({
writeln("before call child");
child.call();
writeln("after call child");
});
parent.call();
% dmd -run co.d
before call child
before call parent
after call child
--- killed by signal 11
-----
Second, I tried Semi-Coroutine code. It works fine.
-----
Fiber child, parent;
child = new Fiber(delegate() {
writeln("before call parent");
Fiber.yield(); // return to parent.
writeln("after call parent");
});
parent = new Fiber({
writeln("before call child");
child.call();
writeln("after call child");
});
parent.call();
% dmd -run co.d
before call child
before call parent
after call child
-----
core.thread.Fiber now provides Semi-Coroutine APIs(call and yield), so I guess former code is invalid.
If so, Fiber's document should describe such limitation.
Comment #1 by alex — 2012-10-09T18:34:06Z
Can you please send a pull request with a doc fix? You probably know the API better than I do.
Comment #2 by robert.schadek — 2024-12-07T13:32:04Z