On 19/04/17 05:00, Ryan Joseph wrote:
On Apr 19, 2017, at 2:34 AM, Daniel Gaspary <dgasp...@gmail.com> wrote:> > Using SetJmp and
LongJmp?> > I believe some months ago it was a discussion on the list on why this> was not really
the way to implement coroutines.> > Searching for longjmp/setjmp you can find the thread, I guess.
I never heard of those functions and I did find a thread about them but it
seemed inconslusive.
Here’s a little test I made not knowing exactly how those functions work. I
expected the stack to be restored and “i” incremented but that’s not what
happens. The program jumps in and out of the loop but “i” remains the same each
time. Is this not how to use those functions?
I thought that Windows implemented "fibers" for this sort of thing?
It is possible to partially-simulate coroutines with setjmp/longjmp, but
you need to store state outside the function. The key thing about
coroutines, at least as implemented by Wirth in Modula-2, is that you
can transfer arbitrarily between them i.e. it's not just a case of a
scheduler selecting one specific task which runs and then returns.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal