[PATCH] D30526: [Support] Add functions to get and set thread name.

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 23:39:28 PST 2017


zturner created this revision.
Herald added subscribers: emaste, srhines, danalbert.

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.


https://reviews.llvm.org/D30526

Files:
  llvm/include/llvm/Support/Threading.h
  llvm/lib/Support/Threading.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30526.90286.patch
Type: text/x-patch
Size: 5278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/a3634501/attachment.bin>


More information about the llvm-commits mailing list