[Haskell-cafe] Getting the 'ThreadId' of the calling thread

Nikita Karetnikov nikita at karetnikov.org
Fri Aug 2 14:41:30 CEST 2013


> Other actions such as withLinksDo and forkLinkIO' insert stuff into
> threadMap. It can be non-mepty.

Thanks (again), Albert.  Later, I found this comment above the
'withLinksDo' function: "It is an error to call this function outside
the main thread, or to call any other functions in this module outside
this function."

Here's the simplest example that doesn't return the exception:

instance Show ThreadId where
  show (Tid u) = show . hashUnique $ u

main = do
  tid  <- C.myThreadId
  tid' <- fmap Tid newUnique
  modifyMVar_ threadMap $ \tm ->
    return $ tm { state = M.singleton tid
                          $ ThreadState { ident     = tid'
                                        , signal    = defaultSignal tid
                                        , links     = S.empty
                                        , monitors  = M.empty
                                        , ownedMons = S.empty } }
  myThreadId
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130802/c10d47b4/attachment.pgp>


More information about the Haskell-Cafe mailing list