如何在MacOSX中设置线程名 [英] how to set a threadname in MacOSX

查看:349
本文介绍了如何在MacOSX中设置线程名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

  • 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?

推荐答案

我建议如下:

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

(您需要添加pthread.h)
在XCode 3.2 .3(至少对于iPhone开发)

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

这篇关于如何在MacOSX中设置线程名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆