SetThreadName 不适用于 Visual Studio 2005

发布于 2024-08-25 23:44:44 字数 626 浏览 1 评论 0原文

SetThreadName 不设置线程名称在 Visual Studio 2005 中,使用方法如下:

DWORD threadId;
HANDLE handle = CreateThread(NULL, stackSize, ThreadFunction,
                             ThreadParam, CREATE_SUSPENDED, &threadId);
if (handle)
{

   SetThreadName(threadId, "NiceName");
   ResumeThread(handle);
}

打开“线程”窗口后,我可以看到 ThreadFunction 的名称,而不是 NiceName。其他工具(如 Intel Parallel Inspector)按预期使用 NiceName。

  • 上面的代码有问题吗?

  • 代码是否适用于 Visual Studio 2008 或 2010 版本?

SetThreadName does not set thread name with Visual Studio 2005, when used as below:

DWORD threadId;
HANDLE handle = CreateThread(NULL, stackSize, ThreadFunction,
                             ThreadParam, CREATE_SUSPENDED, &threadId);
if (handle)
{

   SetThreadName(threadId, "NiceName");
   ResumeThread(handle);
}

After opening the Threads window, instead of NiceName I can see the name of the ThreadFunction there. Other tools (like Intel Parallel Inspector) use NiceName as expected.

  • Is something wrong with the code above?

  • Does the code work with Visual Studio 2008 or 2010 editions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲念泪 2024-09-01 23:44:44

经过几次实验后,我发现这是因为 Visual Studio 试图变得智能,当线程开始执行时,它会为自己命名。解决方法是不要在线程实际启动之前尝试为线程指定名称,实现此目的的最简单方法是从线程函数内部调用 SetThreadName。

我仍然有兴趣知道其他版本的 Visual Studio 是否显示相同的行为。

After a few experiments I have found it is because the Visual Studio is trying to be smart and when the thread begins to execute it gives a name to itself. The workaround is not to try to give the name to thread before the thread has actually started, the easiest way how to achieve this is to call the SetThreadName from inside of the thread function.

Still I would be interested in knowing if other versions of Visual Studio show the same behaviour.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文