xcode 如何在 MacOSX 中设置线程名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2057960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:04:01  来源:igfitidea点击:

how to set a threadname in MacOSX

c++xcodemultithreadinggdb

提问by Albert

In Windows, it is possible to set the threadname via this code. The threadname is then shown in debuggers.

在 Windows 中,可以通过此代码设置线程名。然后在调试器中显示线程名。

In MacOSX, I have seen several hints which indicates that there are threadnames. I think the class NSThread also has a name-attribute. My goal is that I can set the threadname in my C++ application and see it in Xcode/gdb.

在 MacOSX 中,我看到了一些提示,表明存在线程名。我认为类 NSThread 也有一个名称属性。我的目标是我可以在我的 C++ 应用程序中设置线程名并在 Xcode/gdb 中看到它。



Other related questions:

其他相关问题:

回答by Dave H

I recommend the following:

我推荐以下内容:

[[NSThread currentThread] setName:@"My thread name"]; // For Cocoa  
pthread_setname_np("My thread name"); // For GDB.

(You'll need to include pthread.h) Works a treat in XCode 3.2.3 (at least for iPhone development)

(你需要包含 pthread.h)在 XCode 3.2.3 中工作(至少对于 iPhone 开发)

回答by cdespinosa

Which version of Xcode are you using? Thread names are only supported in Mac OS X 10.6 and Xcode 3.2.

您使用的是哪个版本的 Xcode?线程名称仅在 Mac OS X 10.6 和 Xcode 3.2 中受支持。