GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2023-05-09T23:14:05Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/15975semantics of concurrent program depends on -O level, -f[no-]omit-yields2023-05-09T23:14:05Zwaldmann@imn.htwk-leipzig.desemantics of concurrent program depends on -O level, -f[no-]omit-yieldsI am surprised by the behaviour of the program below
(the interesting property is whether it will output "foo").
Behaviours (plural) actually: it seems to depend
on optimisation level, on omit-yields,
and on very small changes in the so...I am surprised by the behaviour of the program below
(the interesting property is whether it will output "foo").
Behaviours (plural) actually: it seems to depend
on optimisation level, on omit-yields,
and on very small changes in the source code:
It does print (mostly), when compiled with -O0.
It does not, when compiled with -O2.
With -O2 -fno-omit-yields, it will print.
With -O0 -fno-omit-yields, and when I remove the two newTVar
in the beginning, it will mostly not print.
How come?
These differences already occur with the
last two lines replaced by "forever $ return ()",
so the STM stuff may be inessential here.
But that's the context where I came across the problem.
See also discussion at https://mail.haskell.org/pipermail/haskell-cafe/2018-November/130274.html
```
import Control.Concurrent.STM
import Control.Concurrent ( forkIO )
import Control.Monad ( forever )
import System.IO
main = do
atomically $ newTVar "bar"
atomically $ newTVar False
forkIO $ putStrLn "foo"
x <- atomically $ newTVar False
forever $ atomically $ writeTVar x True
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.6.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Runtime System |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"semantics of concurrent program depends on -O level, -f[no-]omit-yields","status":"New","operating_system":"","component":"Runtime System","related":[],"milestone":"Research needed","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I am surprised by the behaviour of the program below\r\n(the interesting property is whether it will output \"foo\").\r\n\r\nBehaviours (plural) actually: it seems to depend\r\non optimisation level, on omit-yields,\r\nand on very small changes in the source code:\r\n\r\nIt does print (mostly), when compiled with -O0.\r\nIt does not, when compiled with -O2.\r\nWith -O2 -fno-omit-yields, it will print.\r\nWith -O0 -fno-omit-yields, and when I remove the two newTVar\r\nin the beginning, it will mostly not print.\r\n\r\nHow come?\r\n\r\nThese differences already occur with the\r\nlast two lines replaced by \"forever $ return ()\",\r\nso the STM stuff may be inessential here.\r\nBut that's the context where I came across the problem.\r\n\r\n\r\nSee also discussion at https://mail.haskell.org/pipermail/haskell-cafe/2018-November/130274.html\r\n\r\n\r\n{{{\r\nimport Control.Concurrent.STM\r\nimport Control.Concurrent ( forkIO )\r\nimport Control.Monad ( forever )\r\nimport System.IO\r\n\r\nmain = do\r\n\r\n atomically $ newTVar \"bar\"\r\n atomically $ newTVar False\r\n\r\n forkIO $ putStrLn \"foo\"\r\n\r\n x <- atomically $ newTVar False\r\n forever $ atomically $ writeTVar x True\r\n}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->Research needed