title: How to name a thread in Linux?
body: <p>I have a multithreaded Linux application written in C/C++.  I have <a href="https://stackoverflow.com/questions/149932/naming-conventions-for-threads">chosen names for my threads</a>.  To aid debugging, I would like these names to be visible in GDB, &quot;top&quot;, etc.  Is this possible, and if so how?</p>
  <p>(There are plenty of <a href="https://stackoverflow.com/questions/763041/thread-names-when-do-you-need-to-know-them">reasons to know the thread name</a>.  Right now I want to know which thread is taking up 50% CPU (as reported by 'top').  And when debugging I often need to switch to a different thread - currently I have to do &quot;<code>thread apply all bt</code>&quot; then look through pages of backtrace output to find the right thread).</p>
  <p>The <a href="https://web.archive.org/web/20100322223513/http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.80).aspx" rel="nofollow noreferrer">Windows solution is here</a>; what's the Linux one?</p>