
I writed a little program to test forkIO. in fact, I want to know how to implement the 'select' system call in haskell: module Main where import Control.Concurrent.Chan import Control.Concurrent import System.IO main = do chan <- newChan handles <- mapM ((flip openFile) ReadMode) ["/tmp/a","/tmp/b","/tmp/c"] let readF h = do myID <- myThreadId chan' <- dupChan chan char <- hGetChar h writeChan chan' $ show myID putStrLn [char] threads <- mapM (\h -> forkIO $ readF h) handles nr <- readChan chan mapM killThread $ filter (\x -> show x == nr ) threads putStrLn nr I first mkfifo /tmp/{a,b,c} , then run 'echo "hello" >/tmp/a', then 'runhaskell thisProgram.hs' but I got an error: test.hs: /tmp/b: hGetChar: end of file test.hs: /tmp/c: hGetChar: end of file I think the thread will be blocked when /tmp/b has nothing. but it get EOF, why ? -- Thanks & Regards Changying Li

On 2008 Aug 16, at 12:22, Changying Li wrote:
test.hs: /tmp/b: hGetChar: end of file
test.hs: /tmp/c: hGetChar: end of file
I think the thread will be blocked when /tmp/b has nothing. but it get EOF, why ?
Because FIFOs are odd. Open them for read/write to avoid unexpected EOFs and unexpected blocking. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (2)
-
Brandon S. Allbery KF8NH
-
Changying Li