chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Continuation finalization and delimited continuations


From: megane
Subject: [Chicken-users] Continuation finalization and delimited continuations
Date: Thu, 04 Oct 2012 21:45:38 +0300
User-agent: mu4e 0.9.9-dev4; emacs 24.1.1

Hi there,

I've been playing with the F-operator egg a bit. Specifically, I've made
some simple tests using the %shift/%reset construction. These are the
ones that avoid calling any dynamic wind thunks when calling a
continuation that's not the current one or sth.

Now, does anybody have any idea why this simple example wants to eat all
my memory?

---
(use shift-reset)

(let lp [(i 0)]
  (if (< i 100000000)
      (begin
        (%reset
         (call/cc
          (lambda [k]
            ;; uncomment the next line to see they're getting finalized
            ;;(set-finalizer! k (lambda [k] (print k " is being finalized")))
            (if #t
                (dynamic-wind
                    (lambda [] (begin))
                    (lambda []
                      (if (= 0 (remainder i 100))
                          (print i))
                      (%shift _ #f))
                    (lambda [] (print "out")))
                (%shift _ #f)))))
        (lp (add1 i)))))
---

If you change the #t to #f it doesn't appear to do that.
It seems like the installed dw-thunks are not getting gc'd. 

Should they be?

A related question: Should the dynamic wind thunks be called when the
continuation gets gc'd?

AFAIK the %reset/%shift semantics cannot be implemented in R5RS, and you
cannot escape from a continuation without calling the thunks in R5RS, so
this a Chicken specific question.

I _think_ it would be useful if the out-thunks get called at
continuation gc. I mean, if this could be implemented at all. I guess
you would need to track if the out-thunk was already called or
something.

Currently, if you jump out of, say with-output-to-file, with %shift, and
never return, you would leak file handles. Moreover, you cannot pass
your function that escapes with %shift to an arbitrary function. I mean,
you shouldn't.

Are there other solutions to this resource leak problem other that "use
shift/reset instead of %shift/%reset"?

Kind regards

AC



reply via email to

[Prev in Thread] Current Thread [Next in Thread]