[Top][All Lists]

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

Re: [Chicken-users] Pipe and thread problem

From: Alan Post
Subject: Re: [Chicken-users] Pipe and thread problem
Date: Tue, 23 Oct 2012 16:14:17 -0600

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


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
> _______________________________________________
> Chicken-users mailing list
> address@hidden

.i ma'a lo bradi cu penmi gi'e du

reply via email to

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