[Top][All Lists]

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

Re: [Chicken-users] Asynchronous I/O Egg Release

From: Chris Vine
Subject: Re: [Chicken-users] Asynchronous I/O Egg Release
Date: Thu, 30 Jun 2016 15:13:17 +0100

On Thu, 30 Jun 2016 15:22:41 +0200
Peter Bex <address@hidden> wrote:
> On Thu, Jun 30, 2016 at 02:10:41PM +0100, Chris Vine wrote:
> > Then consider it a bug.  Only sockets from the tcp unit operate in
> > that way, up to chicken-4.10 at least.  For other descriptors you
> > have to use chicken's srfi-18 extension, namely
> > thread-wait-for-i/o!.  
> Can you produce an example program which doesn't behave as expected?

As who is expecting?  It's in the documentation.

As I said, to make this work you have to use thread-wait-for-i/o!  If
you take out the thread-sleep! (so the scheduler isn't forced to try to
read at the outset) you will get a certain amount of output because the
scheduler starts writing some characters and only when it schedules the
read does it block (the block occuring after all the characters in the
buffer have been vacated by read-char). If you do the write in the
worker thread and the read in the main thread then the program jams
immediately, with or without the thread sleep.


(require-extension posix srfi-18)

(let-values (((in out) (create-pipe)))
  (let ((port (open-input-file* in)))
      (lambda ()
        (let loop ()
          (display (read-char port))
  (let ((port (open-output-file* out)))
    (let loop ()
      (let ((cur-time (time->seconds (current-time))))
        (thread-sleep! (seconds->time (+ cur-time 2)))
        (write-char #\x port)
        (flush-output port)

reply via email to

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