Search code examples
c++posix

getting thread name from thread id using posix api


i have a requirment that i have to get thread name from thread id or if that is not possible how to get thread name. Here i am not creating the thread. I am creating the library and this library is used by application and library code will be running in application thread context, i want to print thread name in console log to know that log is comming this particular thread. This should be achieved using posix api's so that it should be portable.

Thanks in advance all for your inputs


Solution

  • As far as I know, posix threads don't have names, but you might use TLS to store a name. See here for an example (not with strings).