Getting Squeak to stop hanging on file I/O (and to start blocking threads on serial)?

Ned Konz ned at bike-nomad.com
Sat Apr 13 15:51:48 UTC 2002


On Saturday 13 April 2002 07:37 am, David T. Lewis wrote:

> Yes, I would like to see this done, but I'm not sure about using
> timeouts to implement it.

I wasn't suggesting using timeouts to implement it. I just thought 
that providing access to the native OS serial character/minimum read 
API (on Unix, VMIN, VTIME in termios; there are corresponding 
controls in Windows) could give better fine-tuning. VTIME completes a 
read when there has been at least VTIME milliseconds between 
characters, and VMIN doesn't complete a read until at least that many 
characters has been received. These can reduce CPU usage.

> The generalized aio support which Lex added to the Unix VM provides
> the necessary underpinnings for Unix platforms. I not sure how it
> would be done for Windows, Mac and RiscOS, but I'm sure that a
> reading of the tcl source will provide the necessary clues.

Perhaps the aio support would work on those platforms. It just uses 
select(); isn't this pretty generally available? Ruby, for instance, 
works on at least Unix and windows and never blocks the entire 
process on file I/O. I remember that Windows' select() is specific to 
sockets, but there is a wait for event there.

> As for the read-with-timeout on Unix and Win, what are the specific
> APIs you are referring to? On Unix, I would expect to just set the
> file to nonblocking mode, then wait for a "file event" indicating
> that the file has become readable, then read all available input
> from the file. This does not involve any timeout behavior. Is this
> more or less what you have in mind?

Yes, for files. See above for a possible enhancement for serial ports. 
If we had the ability to wait for multiple Semaphores at the same 
time, or to raise an exception on another thread (this may be 
possible but I don't know how to do it), we could implement timeouts 
in Smalltalk code.

> In OSProcess for Unix, pipes are set to nonblocking mode, then
> polled for input. The polling part is ugly, and I'd like to be able
> to replace this with an event driven "read all the available
> characters whenever data is available on the channel" as in Tk/tcl.

Absolutely.

> In OSProcess for Windows, I'm struggling with trying to implement
> nonblocking pipes, and it's just plain ugly (I have something
> working, but I'm still getting occasional Windows crashes in
> testing). If there is a way to do a read with timeout on a Win32
> anonymous pipe, please enlighten me before I embarrass myself
> further.

Couldn't you just start another thread and do a non-blocking read on 
the pipe, then signal a (Windows) semaphore? You could then do 
WaitForMultipleEvents on all the semaphores...

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE




More information about the Squeak-dev mailing list