It is often useful however for an application to set the names of its various threads for diagnostic purposes, either when logging or when debugging the application with a debugger that understands how to display thread names.
Because it is extremely non-portable, the methods for getting and setting thread names vary wildly on each platform, and not all operations are supported on every platform.
Regardless, since it is non-critical functionality used mostly for diagnostics, it seems reasonable to provide "best effort" functions, which is what this patch does. This code is a modified version of the logic in LLDB for doing the same thing. If people don't want this, I can always leave it in LLDB, but since it's so hard to make portable and since LLDB has implementations for a lot of different platforms, it might be useful to have it available to anyone who wants it.
Here I provide implementations for the following platforms / operations:
GetName - FreeBSD, NetBSD, Linux.
SetName - Linux, FreeBSD, NetBSD, Apple, Windows.
It's probably possible to do this on many other platforms, but this is already a lot for one person :)
The implementations have already been in use for some time on LLDB so I know they work, but in re-writing the code for LLDB I may have made some syntax errors.
LLVM_ON_WIN32 will never be set in Unix/Threading.inc, will it? Is this branch ever used?