0
有人告诉我,我可以得到pthread相对于其他pthreads(0,1,2等)的索引。获取pthread的索引而不将其作为参数传递给函数。
然而同时使用
pthread_t id = pthread_self();
uint64_t tid;
pthread_threadid_np(NULL, &tid);
给出以下。 (例如,具有4个并行线程)
2134955
2134954
2134956
2134957
232833024
232296448
233369600
233906176
我希望得到在这种情况下,并行线程(0,1,2,3)的索引。这可能没有将它作为参数发送到pthread函数?谢谢您的帮助。
'pthread_t'不一定是算术类型;指针是通用/合理的,实际上它甚至可以是聚合类型('struct')。 –
@R:啊,我正在阅读旧版本的POSIX,这个修改是在第6期中做出的。 – caf