Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
thread i/o
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Hicks <mwh@d...>
Subject: thread i/o
One of the adverisements of OCaml 2.01 was that user-level (not POSIX)
thread I/O is made faster.  The trick used in the implementation is to make
sockets non-blocking, and then only perform a select() when the I/O would
have blocked (by signalling EINTR or EWOULDBLOCK).  However, looking at the
implementation, it looks like in many cases the select() is performed
anyway.  Here is an excerpt from

let rec read fd buff ofs len =
  Thread.wait_read fd;
  try fd buff ofs len
  with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> read fd buff ofs len

The implementation of Thread.wait_read and Thread.wait_write will perform
either a select() or go through the scheduler which will perform the
select().  It seems to me that the implementation should be:

let rec read fd buff ofs len =
  try fd buff ofs len
  with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> 
      Thread.wait_read fd;
      read fd buff ofs len

This way, if I/O is already available, there is no need to do the extra
select().  Am I missing something?

Michael Hicks
Ph.D. Candidate, the University of Pennsylvania            mailto://
"I worked with an individual who plugged his power strip back into itself
and for the life of him could not understand why his computer would not
turn on."