blocking parallel program

Edward Z. Yang ezyang at MIT.EDU
Sat Oct 19 22:47:11 UTC 2013


Hello Facundo,

The reason is that you have compiled the program to be multithreaded, but it
is not running with multiple cores. Compile also with -rtsopts and then
pass +RTS -N2 to the program.

Excerpts from Facundo Domínguez's message of Sat Oct 19 15:19:22 -0700 2013:
> Hello,
>    Below is a program that seems to block indefinitely with ghc in a
> multicore machine. This program has a loop that does not produce
> allocations, and I understand that this may grab one of the cores. The
> question is, why can't the other cores take the blocked thread?
> 
> The program was compiled with:
> 
> $ ghc --make -O -threaded test.hs
> 
> and it is run with:
> 
> $ ./test
> 
> Program text follows.
> 
> Thanks,
> Facundo
> 
> --------
> 
> import Control.Concurrent
> import Control.Monad
> import System.Environment
> 
> main :: IO ()
> main = do
>   y <- getArgs
>   mv0 <- newEmptyMVar
>   mv1 <- newEmptyMVar
>   forkIO $ do
>     takeMVar mv0
>     putMVar mv1 ()
>     loop (y == ["yield"])
>   putMVar mv0 ()
>   takeMVar mv1
> 
> loop :: Bool -> IO ()
> loop cooperative = go
>   where
>     go = when cooperative yield >> go


More information about the Glasgow-haskell-users mailing list