[Stackless] Continuations in stackless

Grant Olson olsongt at verizon.net
Sun May 21 02:48:38 CEST 2006


> 
> It is worse! It is less!
> It is not copying anything than the bare necessary.
> Not the necessary in any sort of "reasonable" way,
> but necessary in the sense of "enough to run at all".
> 
> > Instead of just forking a process (or tasklet in this case)
> > and starting to run it, it creates a factory function that saves a copy
> of a
> > process or tasklet.  This factory function can return and run the forked
> > version of the tasklet over and over.  Hopefully this is somewhat close
> to
> > the real definition.
> 
> Yes, modulo the consequences of the fact that not any local
> or global variable gets saved.
> 

I think that's the key point I was missing.  Locals and globals aren't
preserved, but act in their current 'live' state when the continuation is
executed.  One of the problems I've been running into is that the examples
I'm finding on the web are too simple to illustrate what is really going on.

Apologies for doing the unthinkable on a python mailing list, but this ruby
code cleared things up for me:

irb(main):027:0> def loop
    cont1 = nil
    cont2 = nil
    count  = 1
    callcc{|continuation| cont1 = continuation} if cont1 == nil
    puts count
    count = count + 1
    callcc{|continuation| cont2 = continuation} if cont2 == nil
    puts count
    count = count + 1
    return cont1,cont2
end
=> nil
irb(main):039:0> a = loop()
1
2
=> [#<Continuation:0x38e54a0>, #<Continuation:0x38e5458>]
irb(main):040:0> a[1].call
3
=> [#<Continuation:0x38e54a0>, #<Continuation:0x38e5458>]
irb(main):042:0> a
=> [#<Continuation:0x38e54a0>, #<Continuation:0x38e5458>]
irb(main):043:0> a[0].call
4
5
=> [#<Continuation:0x38e54a0>, #<Continuation:0x38e5458>]
irb(main):044:0> a[1].call
6
=> [#<Continuation:0x38e54a0>, #<Continuation:0x38e5458>]
irb(main):045:0> a[0].call
7
8
=> [#<Continuation:0x38e54a0>, #<Continuation:0x38e5458>]
irb(main):046:0>

That really cleared up why everyone says they're just gotos, because that's
what they are!  Thanks for your time.

-Grant


_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list