Tight loop prevents other threads from running in available cores
The following program does not terminate when compiled with:
ghc --make -O -threaded test.hs
and executed on linux on an amd64 machine with 16 cores with:
./test
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
>>= print
loop :: Bool -> IO ()
loop cooperative = go
where
go = when cooperative yield >> go
Here [1] is the discussion about it so far.
[1] http://www.haskell.org/pipermail/glasgow-haskell-users/2013-October/024412.html
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.6.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Runtime System |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | simonmar |
| Operating system | |
| Architecture |