[Top][All Lists]

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

about coroutines

From: Michele Bini
Subject: about coroutines
Date: Sun, 18 Nov 2001 03:07:58 +0100

I have been encountering some problems (segfaults) while testing
call/cc driven coroutines in guile.  While coroutines are probably not
a commonly found programming paradigm nowadays, i wonder if this is
the symptom of some deeper problem regarding continuation support in

In this example the coroutine 'a' is a loop printing 3 4 5 6 in
succession, while 'b' prints 0 and 1 alternatively.  After a few
seconds executing these loops, guile segfaults with no explicit error
message.  Apparently there is some memory leak or stack allocation
problem going on (scm seems to share the same problem, by the way).

(define (coroutines-test)
  (define x call-with-current-continuation)
  (define w write)
  (define (a y)
    (define l (list 3 4 5 6))
    (let loop ()
      (for-each (lambda (a) (w a) (set! y (x y))) l)
  (define (b y)
    (let loop ((a 1)) (w a) (set! y (x y)) (loop (- 1 a))))
  (let loop ((a a) (b b)) (loop (x a) (x b))))

;; simpler test, triggering the same problem
(define (coroutines-test2)
  (define x call-with-current-continuation)
  (define w write)
  (define (a y)
    (define l (list 1 2 3 4 5))
    (let loop ()
      (for-each (lambda (a) (w a) (set! y (x y))) l)
  (let loop ((a a)) (loop (x a))))


reply via email to

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