This is related to How to assign unique ids to threads in a pthread wrapper? and The need for id_callback when in a multithread environment?.
When we need to differentiate among unique threads, we cannot use functions like pthread_self
because thread ids are reused. In those problems, it was suggested to use a monotonically increasing counter to provide a unique id due to counter potential thread id reuse. The counter is then passed to the thread by way of arg
in pthread_create
.
I don't think we can maintain a map of external thread ids to unique ids because of the reuse problem. The same thread id could have multiple unique ids.
How do we retrieve the arg
passed to pthread_create
from outside the thread? Is it even retrievable?