Skip to content

GHC.Conc.threadStatus - documentation of ThreadDied :: ThreadStatus

Summary

Location of documentation issue: Haddocks for GHC.Conc

The documentation for GHC.Conc.ThreadStatus says:

ThreadDied -- the thread received an uncaught exception

The emphasis should be on received here, because a thread that is created with GHC.Conc.forkIO and that internally throws an exception is reported as having the ThreadStatus ThreadFinished. Only exceptions provoked by GHC.Conc.throwTo result in ThreadDied.

Minimal working example:

import Control.Concurrent
import GHC.Conc

main = mainThread

childThread :: IO ()
childThread = fail "child thread is crashing!"

mainThread :: IO ()
mainThread = do
    child <- forkIO childThread
    threadDelay 5000
    status <- threadStatus child
    putStr "The status of my child is: "
    print status

Proposed improvements or changes

Proposals in order of disruptivity.

  1. At least the documentation should clarify this.
  2. One could change the semantics of GHC.Conc.threadStatus to make the above example print ThreadDied, too.
  3. One might not change the semantics of GHC.Conc.threadStatus but re-name the constuctor ThreadDied to properly reflect its behaviour.

Environment

  • GHC version used (if appropriate):

9.0.2

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information