This is not really a bug, but it comes close since it complicates
application development significantly.
Consider the following Concurrent Haskell program where a reader
thread is forked off to wait for input over the reading end of a
pipe. The main thread attempts after a while to close this
file descriptor.
module Main (
main
) where
import Concurrent
import Posix
import PosixUtil
import GlaExts
main = do {
(r,w) <- createPipe;
forkIO (reader r);
threadDelay 100000;
print "closing pipes";
try (fdClose r);
try (fdClose w);
threadDelay 100000;
print "main thread done";
return ()
} where reader r = do {threadWaitRead (fdToInt r); return ()}
fdToInt :: Fd -> Int
fdToInt (FD# fd#) = I# fd#
try c = catch (c >>= return . Right ) (return . Left)
The outcome of running this little program is that it aborts with:
ewk@hydra% test1
"closing pipes"
AwaitEvent: select failed
ewk@hydra%
Personally I would find application development much easier if (1) the
reader thread was simply garbage collected or (2) the suspended call to
threadWaitRead failed with an error fdClosed or something like that.
(2) is my personal choice since it would allow the reader thread to do
some meaningful work in response to the error, but (1) is ok as well.
However, aborting the whole program is far too extreme for my taste and
the kind of applications that I develop (Unix client-server applications).
Another minor item. The Posix library works with file descriptors of
type Fd, whereas Concurrent Haskell requires integer numbers in a call
to threadWaitRead. The application program must therefore convert the
Fd to an integer. In order to do this, I had to import two additional
modules in order to get hold on the definition of Fd and Int. There
may be smarter ways, but I have not had the time to figure it out.
Cheers
Einar
Strange behaviour of threadWaitRead when closing the file descriptor
Einar Wolfgang Karlsen Thu, 2 Apr 1998 10:30:00 +0200 (MET DST)
- Re: Strange behaviour of threadWaitRead when closin... Einar Wolfgang Karlsen
- Re: Strange behaviour of threadWaitRead when c... Sigbjorn Finne
