Yield from function?
Profile Anaysis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 30 20:12:57 PST 2017
On Monday, 30 January 2017 at 18:48:10 UTC, Ali Çehreli wrote:
> On 01/30/2017 03:03 AM, Profile Anaysis wrote:
> > I need to yield from a complex recursive function too allow
> visualizing
> > what it is doing.
> >
> > e.g., if it is a tree searching algorithm, I'd like to yield
> for each
> > node so that the current state can be shown visually.
>
> I used tree iteration as a Generator example here:
>
> http://ddili.org/ders/d.en/fibers.html
>
> It's in the code where the function 'byNode' appears. (The
> example builds on an earlier tree iteration code in the same
> chapter.)
>
> Ali
I tried your lambda based fib example and it works as
expected(using a function)
But when I try the class version it crashes without a call stack
or any info(somewhere in the fiber module and an access
violation).
import std.stdio, std.concurrency, core.thread;
class Search : Fiber
{
this() { super(&start); }
int res = 0;
void start()
{
Fiber.yield();
res = 1;
}
}
void main()
{
auto search = new Search();
search.call(); writeln(search.res);
search.call(); writeln(search.res);
search.call(); writeln(search.res); // crashes after 3rd
call(first two work fine)
}
Any ideas what why it is crashing like this?
More information about the Digitalmars-d-learn
mailing list