Add threadStatus :: ThreadId -> IO ThreadStatus
authorSimon Marlow <marlowsd@gmail.com>
Thu, 10 Jul 2008 15:17:11 +0000 (15:17 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Thu, 10 Jul 2008 15:17:11 +0000 (15:17 +0000)
commitb77412cf5fbeb9262464a3405a8baf3fc38f54cc
treef8fca47fe37115cc6e984ef91bb48e4a8c2a0009
parent9eda37c15cdfc33cadfa95001c807273679a2fc2
Add threadStatus :: ThreadId -> IO ThreadStatus

-- | The current status of a thread
data ThreadStatus
  = ThreadRunning
        -- ^the thread is currently runnable or running
  | ThreadFinished
        -- ^the thread has finished
  | ThreadBlocked  BlockReason
        -- ^the thread is blocked on some resource
  | ThreadDied
        -- ^the thread received an uncaught exception
  deriving (Eq,Ord,Show)

data BlockReason
  = BlockedOnMVar
        -- ^blocked on on 'MVar'
  | BlockedOnBlackHole
        -- ^blocked on a computation in progress by another thread
  | BlockedOnException
        -- ^blocked in 'throwTo'
  | BlockedOnSTM
        -- ^blocked in 'retry' in an STM transaction
  | BlockedOnForeignCall
        -- ^currently in a foreign call
  | BlockedOnOther
        -- ^blocked on some other resource.  Without @-threaded@,
        -- I/O and 'threadDelay' show up as 'BlockedOnOther', with @-threaded@
        -- they show up as 'BlockedOnMVar'.
  deriving (Eq,Ord,Show)

This is useful for concurrency debugging.  I've left threadStatus in
GHC.Conc for now, since the ThreadStatus type is somewhat GHC-specific.
GHC/Conc.lhs