How do you set the name of a thread in C++?
This is not an MFC application. Currently, I'm using _beginthreadex to create the thread.
This is not an MFC application. Currently, I'm using _beginthreadex to create the thread.
1. Immediately after CreateThread(...), call SetThreadName(...). This doesn't seem to have any effect. The name reverts back to the name of the supplied ThreadProc, so I'm assuming either the debugger doesn't know about the thread yet, so ignores the exception, or it is overwritten when the thread starts. In this case, the thread ID I'm using is directly back from the call to CreateThread(...). This would be my preferred method, since the name is set before the thread entry, which would aid in debugging.
2. Call SetThreadName(-1, <name>) when the ThreadProc is called. This does work for me. It is a little bit of a pain to get the mechanism in place, but it works.
3. Just before the ThreadProc is called, try to SetThreadName(...) using the m_pid from CreateThread(...). This seems to work some of the time, but not reliably.
Thanks for your help on this one...