guile-user
[Top][All Lists]
Advanced

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

Re: about coroutines


From: Marius Vollmer
Subject: Re: about coroutines
Date: 19 Nov 2001 14:27:39 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

Keith Wright <address@hidden> writes:

> This answers the question I forgot to ask.  It looks like we have two
> distinct bugs here then.
> 
>    *bug1 - segfault without error message on stack (heap?) overflow.

Yes, confirmed.

>    *bug2 - obscure memory leak in certain uses of call/cc

Confirmed as well.  This version of coroutines works:

    (define call/cc call-with-current-continuation)

    (define next (make-fluid))

    (define (run-coroutines . procs)
      (with-fluids ((next (cdr procs)))
        ((car procs))))

    (define (yield)
      (call/cc (lambda (k)
                 (let ((n (fluid-ref next)))
                   (cond ((not (null? n))
                          (fluid-set! next (append (cdr n) (list k)))
                          ((car n))))))))

    (define (coroutine-a)
      (define l (string->list "Hello, world!\n"))
      ;; print hello world
      (let loop ()
        (for-each (lambda (a)
                    (write-char a)
                    (yield))
                  l)
        (loop)))

    (define (coroutine-b)
      (let loop ((a 1))
        (write a)
        (yield)
        (loop (- 1 a))))

    (run-coroutines coroutine-a coroutine-b)

I don't know why, yet.



reply via email to

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