-fno-omit-yields doesn't work at -O0
import Control.Concurrent
import Control.Monad
main = do
forkIO $ forever $ return ()
threadDelay 100000
putStrLn "done!"
In #8521 (closed) compiling with -fno-omit-yields
was suggested, in order to make the tight loop yield. This appears to work at -O1
:
$ ghc -O1 -threaded -fno-omit-yields Bug.hs
[1 of 1] Compiling Main ( Bug.hs, Bug.o ) [Optimisation flags changed]
Linking Bug ...
$ ./Bug +RTS -N2
done!
...but not at -O0
:
$ ghc -O0 -threaded -fno-omit-yields Bug.hs
[1 of 1] Compiling Main ( Bug.hs, Bug.o ) [Optimisation flags changed]
Linking Bug ...
$ ./Bug +RTS -N2
^C^C
Also, I don't understand why -fno-omit-yields
is at all required when running with -N2
. If the forever $ return ()
thread hogs one capability without yielding, wouldn't there be a second one left for the main thread to run on?
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5