Hello Neil, Tuesday, April 7, 2009, 6:13:29 PM, you wrote:
> Calls to System.Cmd.system, i.e. running external console processes. > It's a make system I'm writing, so virtually all the time is spent in > calls to ghc etc. > To Bulat: I should have been clearer with the spec. The idea is that > multiple calls to paralell_ can execute, and a function executing > inside parallel_ can itself call parallel_. For this reason I need one > top-level thread pool, which requires unsafePerformIO. If I create a > thread pool every time, I end up with more threads than I want. this is smth new to solve i propose to use concept similar to Capability of GHC RTS: we have one Capability provided by thread calling para and N-1 Capabilities provided by your thread pool. all that we need is to reuse current thread Capability as part of pool! para xs = do sem <- newQSem for xs $ \x -> do writeChan chan (x `finally` signalQSem sem) tid <- forkIO (executing commands from chan...) waitQSem sem killThread tid instead of killThread we really should send pseudo-job (like my Nothing value) that will led to self-killing of job that gets this signal this solution still may lead to a bit more or less than N threads executed at the same time. your turn! -- Best regards, Bulat mailto:bulat.zigans...@gmail.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe