[Haskell-cafe] Bringing Erlang to Haskell

Bulat Ziganshin bulatz at HotPOP.com
Tue Dec 13 06:17:07 EST 2005


Hello Joel,

Tuesday, December 13, 2005, 1:05:10 PM, you wrote:
>> are you read dewscription of my own Process library in haskell
>> maillist?

JR> No. Can you give me a pointer?

i will forward it to you. it have meaning to be subcribed there, just
to see interesting announcements

>> btw, i suggested you to try not using logging thread entirely, making
>> all logging actions synchronously

JR> I cannot. Only one thread can use stdout, otherwise the output is  
JR> garbled. Plus, combing through a few thousand individual files  
JR> produced by the threads would be a pain.

:)))

import Control.Concurrent
import Control.Monad
import System.IO
import System.IO.Unsafe

main = do h <- openBinaryFile "test" WriteMode
          for [1..100] $ \n ->
            forkIO $
              for [1..] $ \i ->
                logger h ("thread "++show n++" msg "++show i)
          getLine
          hClose h

lock = unsafePerformIO$ newMVar ()

logger h msg = withMVar lock $ const$ do
                 hPutStrLn h msg
                 putStrLn msg

for = flip mapM_

-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Haskell-Cafe mailing list