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
how to set a threadname in MacOSX
提问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:
其他相关问题:
- Can I set the name of a thread in pthreads / linux?(with a very good answer/overview for pthread here)
- How to name a thread in Linux?
- How to set name to a Win32 Thread?(also interesting is this discussion by Bruce Dawson)
- (Android) How to set name to the thread?
回答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 中受支持。