signal handler doesn't retain data
GHC's runtime is too eager to report "no threads to run:
infinite loop or deadlock?". Consider the program
below. The program forks a subprocess, then waits on a
`readChan`, expecting it to be satisfied by the SIGCHLD
signal handler once the subprocess completes execution.
But GHC immediately fails with the "no threads to run"
message. I think this is inappropriate. The runtime
system should realize that a signal handler exists that
could satisfy the `readChan` request.
There is a workaround: Keep an extra thread around that
simply spins its wheels, say by repeating `threadDelay`
indefinitely. I find this rather ugly, however.
import Concurrent
import Posix
main = do
queue <- newChan
installHandler sigCHLD (Catch (handler queue)) Nothing
mpid <- forkProcess
case mpid of
Nothing -> executeFile "Sigchld-sub" True [] Nothing
Just pid -> return ()
status <- readChan queue
return ()
handler queue = do
status <- getAnyProcessStatus True False
writeChan queue status
Trac metadata
Trac field |
Value |
Version |
5.02 |
Type |
Bug |
TypeOfFailure |
OtherFailure |
Priority |
normal |
Resolution |
ResolvedFixed |
Component |
Runtime System |
Test case |
|
Differential revisions |
|
BlockedBy |
|
Related |
|
Blocking |
|
CC |
|
Operating system |
|
Architecture |
|