Re: Re[2]: [Haskell-cafe] Bringing Erlang to Haskell

2005-12-13 Thread Joel Reymont
Thank you Bulat, makes total sense. This list is a treasure trove of  
a resource.


I guess this is what happens when you go from Erlang to Haskell :-).  
I'm conditioned to think of everything as a process and uses  
processes for everything.


On Dec 13, 2005, at 11:17 AM, Bulat Ziganshin wrote:


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_


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Bringing Erlang to Haskell

2005-12-13 Thread Bulat Ziganshin
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,
 Bulatmailto:[EMAIL PROTECTED]



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Bringing Erlang to Haskell

2005-12-13 Thread Bulat Ziganshin
Hello Tomasz,

Tuesday, December 13, 2005, 12:49:04 PM, you wrote:

TZ> On Mon, Dec 12, 2005 at 04:00:46PM +, Joel Reymont wrote:
>> One particular thing that bugs me is that I cannot really use TChan  
>> for thread mailboxes. I don't think I experienced this problem with  
>> Erlang but using a TChan with a logger thread quickly overwhelms the  
>> logger and fills the TChan and a lot (hundreds? thousands) of other  
>> threads are logging to it. 

TZ> I wonder what Erlang does to solve this problem? Perhaps we should track
TZ> the number of unprocessed messages in TChans and the bigger it is
TZ> the more favor consumers over producers.

even best - always prefer consumer to producer :)  may be have two
lists - one of threads waiting to consume, and one of threads waiting to
produce?



-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe