[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: about coroutines
From: |
Michele Bini |
Subject: |
Re: about coroutines |
Date: |
Sun, 18 Nov 2001 08:19:13 +0100 |
>>>>> "Keith" == Keith Wright <address@hidden> writes:
Keith> I do not get a segfault (Guile 1.5.4). I get execution
Keith> starting off fairly quickly but getting slower and slower
Keith> with long pauses and sucking up all compute cycles until I
Keith> kill it, which is not easy because bash starts to take half a
Keith> minute to echo a character.
Well, this is not what seems to happen under other scheme
implementations, MIT Scheme is able to run these loops indefinitely
without increasing in memory usage, so i assume that there is
something wrong with guile and scm (also my scheme-scheme interpreter
runs this fine; although, well, i don't claim my implementation to be
perfect).
Keith> I blame the OS (obsolete Linux version) for not giving bash a
Keith> decent time slice. An error message when you run out of
Keith> storage would be a good thing. This program does segfault
Keith> after a few seconds:
Keith> (define (test) (let loop ((x '())) (loop (cons x x))))
Yep this one makes guile crash much faster, even here :).
Keith> I don't really understand your program. Why do you think it
Keith> is not essentially equivalent to this one? It seems to be
Keith> creating continuations at a furious rate and doing the same
Keith> as mine, only with stack frames instead of cons cells.
Well, the main difference is that my test program is not supposed to
allocate memory that the garbage collector can not free, and the
continuations it creates should get garbage collected once they are no
more referenced. BTW, the second test i posted was not really a
coroutine example, but is just a simplified version of the first that
triggers the same problem.
;; a less obfuscated example :) (hereby placed into the public domain)
(define (coroutines-test)
(define x call-with-current-continuation)
(define (coroutine-a y)
(define l (string->list "Hello, world!\n"))
;; print hello world
(let loop ()
(for-each
(lambda (a)
(write-char a)
(set! y (x y)) ;; yield
)
l)
(loop)))
(define (coroutine-b y)
;; print alternatively 1 and 0
(let loop ((a 1))
(write a)
(set! y (x y)) ;; yield
(loop (- 1 a))))
(define (run-concurrently . coroutines)
(apply run-concurrently (map x coroutines)))
(run-concurrently coroutine-a coroutine-b))
Michele
- about coroutines, Michele Bini, 2001/11/17
- Re: about coroutines, Keith Wright, 2001/11/18
- Re: about coroutines,
Michele Bini <=
- Re: about coroutines, Keith Wright, 2001/11/18
- Re: about coroutines, Marius Vollmer, 2001/11/19
- Re: about coroutines, Keith Wright, 2001/11/19
- Re: about coroutines, Michele Bini, 2001/11/19
- Re: about coroutines, Marius Vollmer, 2001/11/21
- Re: about coroutines, Michele Bini, 2001/11/22
- Re: about coroutines, Marius Vollmer, 2001/11/29
- Re: about coroutines, mibin, 2001/11/30