[Top][All Lists]

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

[Chicken-users] Pipe and thread problem

From: Aaron Patterson
Subject: [Chicken-users] Pipe and thread problem
Date: Tue, 23 Oct 2012 14:30:57 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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

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)
       (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)
       (lambda ()
         (print "consumer started")
         (let loop ()
           (print (read-line reader))
    (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

reply via email to

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