forkIO has inconsistent behavior under optimization
Troubleshooting the T4030 failure in SimonPJ's early-inline branch, Reid and I discovered that the problem showed up when the argument to forkIO
was obviously bottom. He came up with a tiny test case that fails without Simon's changes:
main = forkIO undefined >> threadDelay 1000000
It looks like the trouble is in the definition of forkIO
:
forkIO :: IO () -> IO ThreadId
forkIO action = IO $ \ s ->
case (fork# action_plus s) of (# s1, tid #) -> (# s1, ThreadId tid #)
where
action_plus = catchException action childHandler
This seems to run into the trouble with catchException
and strictness explained in GHC.IO
. It would appear that the conservative fix would be to replace catchException
with catch
. Personally, I find it a bit surprising that forkIO
doesn't force its IO
argument before forking, but changing that behavior could break working code.
Trac metadata
Trac field | Value |
---|---|
Version | 8.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Core Libraries |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |