0

Right now I'm doing this:

std::cout << pthread_self() << std::end;

But it seems like that returns a hexadecimal number. How can I get the actual thread ID in decimal form using some function in the pthread_t.h library?

Ryan
  • 647
  • 2
  • 7
  • 17
  • 2
    You can't get that information from the pthreads API because the pthreads API is designed to be portable -- in particular, it's designed to work even on systems that don't have integer thread IDs. That's why pthread_self() returns an implementation-defined/opaque type (pthread_t) rather than a more concrete type, and why you can't even e.g. compare pthread_t values using the == operator (you have to call pthread_equals() instead). The short answer is: you'll need to use an OS-specific API (like gettid()) to get the information you want. – Jeremy Friesner May 13 '15 at 04:44
  • possible duplicate of [How do I get a thread ID from an arbitrary pthread\_t?](http://stackoverflow.com/questions/558469/how-do-i-get-a-thread-id-from-an-arbitrary-pthread-t) – Nikolay K May 13 '15 at 06:37
  • Why do you care? If you need to uniquely identify a thread, just assign them your own ids. – i_am_jorf May 13 '15 at 07:06

1 Answers1

0

If you want threads to have an ID that meets certain requirements, assign them one. They won't "just happen to have one" without you doing something to make it happen.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278