[Haskell-cafe] Go parallel

Tim Docker timd at macquarie.com.au
Mon Nov 5 19:44:37 EST 2007


Thanks - I was aware of par and it's ilk, but I couldn't imagine any
way of doing the latter... how can you actually force something pure to
get
calculated in a worker thread?

But thinking now, I guess judicious use of seq or deepseq is
appropriate.
Something like this might work.

workerThread :: (a->b) -> MVar a -> MVar b -> IO ()
workerThread f inp out = do
    a <- takeMVar inp
    let b = f a in (b `seq` putMVar out b)
    workerThread f inp out

In a spare moment I'll have to give it a go.

Tim

-----Original Message-----
From: Don Stewart [mailto:dons at galois.com] 
Sent: Tuesday, 6 November 2007 11:16 AM
To: Tim Docker
Cc: haskell-cafe at haskell.org; Bulat Ziganshin
Subject: Re: [Haskell-cafe] Go parallel

timd:
> Is it possible to use the forkIO primitive to cause pure computations 
> to be evaluated in parallel threads?
> 
> It seems to me that laziness would always prevent any evaluation until

> the result was used in a consuming thread (and hence would occur 
> serially, in that thread).

Try `par` and friends in Control.Parallel. You can also build
referentially transparent worker gangs on top of forkIO.

--  Don


More information about the Haskell-Cafe mailing list