This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: continuation and multi-threading


Keisuke Nishida <kxn30@po.cwru.edu> writes:

> Mikael Djurfeldt <mdj@mdj.nada.kth.se> writes:
> 
> > Continuations really are quite simple.  In a way, what `call/cc' does
> > is that it makes a procedure (called "continuation") out of the
> > context of the call to `call/cc' so that you can invoke what is
> > supposed to happen after the `call/cc' at any time later:
> (snip)
> > You can probably implement it simply by taking a copy of the stack,
> > and that implementation is OK for Guile.
> > 
> > But it's still important that you understand them (something which I
> > expect you to do within a couple of hours).
> 
> Okay, I got it.  So a call of a continuation never returns, right?
> In that case, I can implement it this way:
> 
>  1. When call-with-current-continuation is called, the VM copies
>     the current stack and registers, and creates a continuation object
>     with them.
> 
>  2. The VM calls a closure with the continuation in the regular way.
> 
>  3. If the closure finishes without calling the continuation,
>     nothing happens.  It continues execution.
> 
>  4. Whenever a continuation is called, the VM throws out the current
>     stack and recovers the stack and registers that the continuation has.
>     It arranges the return value, and then continues execution.
> 
> I think that's it.  Since the VM clears the stack when a continuation
> is called, stack overflow won't happen.  Is that right?

If you want to support dynamic-wind in combination with continuations,
there is some additional book keeping to be done, and winding and
unwinding thunks to call.  'Essentials of Programming Languages',
Section 9.5 has a discussion of this topic.

-russ


--
"Don't be too proud of this technological terror you've constructed."
             -- Darth Vader

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]