chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Threads and blocking on interpreter input


From: felix
Subject: Re: [Chicken-users] Threads and blocking on interpreter input
Date: Fri, 04 Apr 2003 21:47:31 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529

Chris Double wrote:
I wanted to run some threads in the background while also using the read-eval-print loop in the csi. While csi is waiting for input it blocks all threads it seems (does this include threads waiting on tcp calls?).

Yep, all input blocks other thread with the exception of tcp-accept and
I/O from ports returned by tcp-accept and tcp-connect.


As a workaround I came up with the following which allows threads to run in the background while the listener is waiting for input:

(set! ##sys#read-prompt-hook
          (lambda ()
                (when (or (##sys#fudge 12) (##sys#tty-port? 
(current-input-port)))
                          (display ">>> ")
                          (flush-output)
                          (##sys#thread-block-for-i/o! ##sys#current-thread 0 
#t)
                          (thread-yield!))))

It's a hack, and probably won't work in all circumstances, but it worked for what I needed to do. Is there a more robust way of doing this or are there future plans for making terminal and file i/o not block threads?

That is a hack, indeed! ;-) But if it does what it should, fine
(Your code assumes current-input-port is stdin (fd 0), but otherwise
it looks safe enough. Also, a context switch betweem ##sys#thread-block-for-i/o!
and thread-yield! could be problematic. I would add a `disable-interrupts'
declaration in the module that contains this code).

Having fully non-blocking I/O is *generally* possible. The infrastructure
is there. But I think the I/O subsystems needs an overhaul anyway. It's
pretty slow.

Anybody interested in helping me with this?


cheers,
felix






reply via email to

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