[MLton] callcc and space use

Daniel Spoonhower spoons at cs.cmu.edu
Wed Jan 23 05:03:42 PST 2008


> In summary, assuming my understanding of the implementation is
> correct, using callcc+throw to spawn a new thread and perform N
> suspends and resumes takes O((N+1)*S) time, where S is the average
> stack size, while the same with threads takes O(N+1) time.

This is my understanding as well.  I have been using callcc & throw as 
part of my library because they allow me to write parallel programs in a 
natural way (or so it seems to me).  I'm aware of the thread copy that 
this incurs, but I expected the overhead in both time and space to be 
constant (assuming a bounded stack size).  I have some ideas about how 
to avoid this overhead, but for now any constant is fine with me.  My 
concern is that the space use is asymptotically larger than I expect.

I attached a small(-ish) example.  It copies and reverses a list of 
reals.  Toward the end of execution there are more than 4000 live cons 
cells in the heap, though the length of the input list is only 75.


--djs

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple.sml
Type: application/smil
Size: 1906 bytes
Desc: not available
Url : http://mlton.org/pipermail/mlton/attachments/20080123/693b895d/simple.smil


More information about the MLton mailing list