[GHC] #10639: Optimization changes concurrent program's behaviour
GHC
ghc-devs at haskell.org
Wed Jul 15 05:21:34 UTC 2015
#10639: Optimization changes concurrent program's behaviour
-------------------------------------+-------------------------------------
Reporter: gizmo.mk0 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.1
Resolution: | Keywords:
Operating System: Windows | Architecture: x86_64
Type of failure: Incorrect result | (amd64)
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by gizmo.mk0:
Old description:
> Here is a program that spawns a thread from the main thread, which tries
> to constantly write out a message to the console.
>
> {{{#!hs
> module Main where
>
> import Control.Concurrent (forkIO)
>
> main :: IO ()
> main = do
> _ <- forkIO $ runForever $ putStrLn "Hey"
> runForever $ return ()
>
> runForever :: IO () -> IO ()
> runForever action = action >> runForever action
> }}}
>
> If you compile it with 'ghc main', it works correctly - it prints out the
> message continuously, and you can terminate it by pressing Ctrl-C.
> However, if you compile it with 'ghc -O main' (or -O2, or -O3...), it
> doesn't print out anything, and the only way to exit is to kill the
> process from Task Manager.
>
> This was reproducable with GHC 7.10.1, on a Windows 7 x64 machine, with
> an AMD A4-5300 APU.
>
> ''(Disclaimer: this is my first bugreport, and I'm not sure what else can
> I do to investigate this issue.)''
New description:
Here is a program that spawns a thread from the main thread, which tries
to constantly write out a message to the console.
{{{#!hs
module Main where
import Control.Concurrent (forkIO)
main :: IO ()
main = do
_ <- forkIO $ runForever $ putStrLn "Hey"
runForever $ return ()
runForever :: IO () -> IO ()
runForever action = action >> runForever action
}}}
If you compile it with 'ghc main', it works correctly - it prints out the
message continuously, and you can terminate it by pressing Ctrl-C.
However, if you compile it with 'ghc -O main' (or -O2, or -O3...), it
doesn't print out anything, and the only way to exit is to kill the
process from Task Manager.
This was reproducable with GHC 7.10.1, on a Windows 7 x64 machine, with an
AMD A4-5300 APU.
''EDIT: As it turns out, using "yield" instead of "return ()" solves the
problem. It seems I misunderstood how forkIO works. However, I'm not sure
if the current working is intentional or not, so I think I should leave
this ticket open - just to be on the safe side.''
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10639#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list