[Haskell-cafe] semantics of concurrent program depends on -O level, -f[no-]omit-yields

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Fri Nov 30 10:50:03 UTC 2018


> the same thread might be schedule immediately again, and again, ... Or
> do we have some specification of the scheduler? 

My working assumption is that the scheduler tries to be fair.
So all strange behaviour could be explained with the scheduler
not running at all, because threads weren't yielding.

> The question where scheduling can actually happen is a totally different
> issue, and I don't know of a specification here, either. In GHC, this
> seems to be tied to allocations, but this is a bit brittle and
> unintuitive. 
Yes, especially if the compiler might (re)move allocations
due to some code transformations.

Given that, it now feels strange that the following *does* work:

main = do
  forkIO $ do threadDelay 1000000 ; putStrLn "foo"
  forever $ putStr ""

I am seeing the "foo" output. I expect the last line
to be non-allocating. But it does still yield? Why?

- J.W.

More information about the Haskell-Cafe mailing list