[fpc-pascal] Coroutines and VirtualAlloc

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Wed Apr 19 10:28:20 CEST 2017

On 19/04/17 05:00, Ryan Joseph wrote:
>> On Apr 19, 2017, at 2:34 AM, Daniel Gaspary <dgaspary at 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]

More information about the fpc-pascal mailing list