It often happens to me when debugging or playing around in GHCi that I happen to know the actual ThreadId
number (for example from using Debug.Trace
), but that's all I have.
The problem is that all thread APIs, such as killThread
require a ThreadId
and not an Int
.
I've tried Hoogle but came out empty. Is there a way to do this? I'm concerned mostly with debugging, so I don't mind if it's a nasty hack or if it's through a GHC-only library.
You can't.
ThreadId
is abstract. TheInt
you have is actually nothing more than a counter (source):It's
rts_getThreadId
that gets called inThreadId
'sShow
instance. There's no mapping back to the actual TSO. If you want to know whatThreadId
belongs to whatInt
, you need to keep track of them yourself. You could, for example, parse theInt
and fill aMap
.