For me, that program is blocking on a call to poll(), which must be something that is happening in chicken's threading code.
It is polling on two file descriptors with an infinite timeout, and clearly never coming back up for air. the produce thread is hanging on the thread-sleep call, and the consume thread is hanging on the read-line call. This means (and I confirm in the ktrace) that your pipe is being written to. If I add a (newline writer) between your write and your flush, read-line finishes once (I'd expect that) and then blocks again on read-line, but the writing thread never wakes up. I'm not sure why a (thread-sleep! 1) would ever cause poll to be called with an infinite timeout, but a quick analysis shows that some case is not waking up produce and you get to a point where both ends of the pipe are waiting for the other one. Anyone with a better understanding of Chicken's internals able to comment on which cases poll() is called and how the timeout value is selected? -Alan On Tue, Oct 23, 2012 at 02:30:57PM -0700, Aaron Patterson wrote: > Hi, I'm trying to simulate reading from a TTY that writes every two > seconds. I want to do this with a pipe and two threads, one thread > writes every N seconds, while the other reads any data available on the > pipe. > > Unfortunately, my code just hangs. After speaking with the fine people > in #chicken, it seems that this may be a bug. We played with different > calls to put the threads to sleep, and different functions to read data, > but they all ended up freezing at some point. > > Here is the program: > > (use srfi-18) > (use posix) > > (define (produce writer) > (thread-start! > (lambda () > (print "producer started") > (let loop ((i 0)) > (display (conc "hello" i " ") writer) > (flush-output writer) > (thread-sleep! 1) > (loop (+ i 1)))))) > > (define (consume reader) > (thread-start! > (lambda () > (print "consumer started") > (let loop () > (print (read-line reader)) > (loop))))) > > (define (stream-test in-fd out-fd) > (let ((reader (open-input-file* in-fd)) > (writer (open-output-file* out-fd))) > (produce writer) > (thread-join! (consume reader)))) > > (call-with-values create-pipe stream-test) > > Any help would be greatly appreciated. Thanks! > > -- > Aaron Patterson > http://tenderlovemaking.com/ > > _______________________________________________ > Chicken-users mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/chicken-users -- .i ma'a lo bradi cu penmi gi'e du _______________________________________________ Chicken-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-users
