pthread_setname_np - a few notes
During debugging a particularly evasive problem I needed to see the CPU usage of each thread in a program.
My cunning plan was to use pthread_setname_np() so I can see the thread names of a program and their CPU use in htop. It works but there are two gotchas:
- thread names are inherited in Linux, so if a thread names itself "cucumber" then all threads it starts with pthread_create will inherit that name (they can rename themselves afterwards).
- htop picks up new threads almost immediately but not changed pthread names, so you have to exit+restart htop to see the correct thread names.
I hope this helps someone some day.