[MLton] callcc and space use

Daniel Spoonhower spoons at cs.cmu.edu
Tue Jan 22 07:31:19 PST 2008


Hi, all.

I've been using callcc/throw in some of my parallel work as a means to 
suspend and resume computation.  I've come across a bit of a problem in 
terms of the performance of this strategy, and I am wondering if someone 
can confirm some of my suspicions.

My concern is that variables which are allocated to the stack but *not* 
live at the point at which callcc is invoked are nonetheless captured by 
the continuation.  I believe this leads to a space leak in some cases. 
Does this sound plausible?

For example, consider:

   fun f x =
      let val y = ... x ... in
        (* no more occurrences of x *)
        callcc (fn k => (enq (fn () => ... k ...);
                         raise Continue))
      end

Assuming that "x" is allocated on the stack, there will be a reference 
to it when callcc copies the current thread.  Of course the reference on 
the original thread will go away when the exception is raised, but the 
one in the copy seems to persist.

My inclination would be to try to null out references on the stack that 
are not live across certain C calls (e.g. GC_copyCurrentThread), but I'd 
be happy to hear other suggestions as well.

Thanks!

--djs



More information about the MLton mailing list