How can I build a ThreadId given that I know the actual number?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 17:44:07

You can't. ThreadId is abstract. The Int you have is actually nothing more than a counter (source):

32  static StgThreadID next_thread_id = 1;
...
59  StgTSO *
60  createThread(Capability *cap, W_ size)
61  {
62      StgTSO *tso;
...
126     ACQUIRE_LOCK(&sched_mutex);
127     tso->id = next_thread_id++;  // while we have the mutex
...
130     RELEASE_LOCK(&sched_mutex);
...
136 }
...
161 int
162 rts_getThreadId(StgPtr tso) 
163 {
164   return ((StgTSO *)tso)->id;
165 }

It's rts_getThreadId that gets called in ThreadId's Show instance. There's no mapping back to the actual TSO. If you want to know what ThreadId belongs to what Int, you need to keep track of them yourself. You could, for example, parse the Int and fill a Map.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!