[fpc-pascal] Coroutines and VirtualAlloc

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Wed Apr 19 11:57:44 CEST 2017


On 19/04/17 09:30, Ryan Joseph wrote:
>> On Apr 19, 2017, at 3:28 PM, Mark Morgan Lloyd <markMLl.fpc-pascal at telemetry.co.uk> wrote:> > 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.
> I only used coroutines in Lua and they were basically a way for a control structure like a loop to return control the main program without using threading. From the descriptions it sounds like longjmp moves the current point of execution of the program (if that concept exists like I imagine it does) so you could step in and out of loops or functions. If not that then what do those functions actually do?

SetJmp records the current state, LongJmp reverts to it. There's some 
common-sense limitations.

I've got an example program of about 100 lines that would demonstrate 
what I've hacked together, I could tack it onto a message if the ML 
managers consider that acceptable.

-- 
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