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

David T. Lewis lewis at mail.msen.com
Sat Apr 13 14:37:36 UTC 2002


On Fri, Apr 12, 2002 at 09:41:34AM -0700, Ned Konz wrote:
> This has been discussed before, but no agreement came out of that 
> discussion. The problem with my making changes to this behavior in 
> Unix is that it would have to be ported to every platform.
> 
> I hesitate to call this a [BUG]; it's more of a design malfeature.

indeed.
 
> Now that we have the sqaio support for sockets, why aren't we using it 
> for regular file handles and for serial I/O?
 
[snip]

> What I'd like to see is for the reads or writes on files and serial 
> ports to block the calling thread until complete or timed out.
> 
> An alternative, of course, would be to come up with a NewSerialPlugin 
> and a NewFilePlugin that do the right thing.
> 
> Any thoughts on this?

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

I think that the Tk/Tcl event model is pretty much the right design
to follow. It's simple, clean, portable across a range of platforms, and
the design fits nicely with the way Squeak works. In a nutshell:

- There is a generalized concept of an IO channel, representing things
  like files and sockets.
- The VM receives events corresponding to (for example) data available
  to read from a channel. See man(n) fileevent if you have tcl on your
  system.
- Event handlers respond to events (for example, read the available data
  from a channel).

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.

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?

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.

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.

Dave




More information about the Squeak-dev mailing list