Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- mkWeakThreadIdWithFinalizer :: ThreadId -> IO () -> IO (Weak ThreadId)
- addThreadFinalizer :: ThreadId -> IO () -> IO ()
- finalizeThread :: Weak ThreadId -> IO ()
Documentation
mkWeakThreadIdWithFinalizer :: ThreadId -> IO () -> IO (Weak ThreadId) Source #
A variant of mkWeakThreadId
that supports
finalization.
Make a weak pointer to a ThreadId
. It can be important to do
this if you want to hold a reference to a ThreadId
while still
allowing the thread to receive the BlockedIndefinitely
family of
exceptions (e.g. BlockedIndefinitelyOnMVar
). Holding a normal
ThreadId
reference will prevent the delivery of
BlockedIndefinitely
exceptions because the reference could be
used as the target of throwTo
at any time, which would unblock
the thread.
Holding a Weak ThreadId
, on the other hand, will not prevent the
thread from receiving BlockedIndefinitely
exceptions. It is
still possible to throw an exception to a Weak ThreadId
, but the
caller must use deRefWeak
first to determine whether the thread
still exists.
addThreadFinalizer :: ThreadId -> IO () -> IO () Source #
A specialised version of mkWeakThreadIdWithFinalizer
, where the Weak
object
returned is simply thrown away (however the finalizer will be
remembered by the garbage collector, and will still be run
when the key becomes unreachable).