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

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

问题描述

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

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

在 MacOSX 中,我看到了一些提示,表明存在线程名.我认为类 NSThread 也有一个名称属性.我的目标是我可以在我的 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?
  • How to set name to a Win32 Thread? (also interesting is this discussion by Bruce Dawson)
  • (Android) How to set name to the thread?

推荐答案

我推荐如下:

[[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天全站免登陆