views:

193

answers:

2

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

Under Linux, see this question.

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.

+2  A: 

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

cdespinosa
I am using OSX 10.5 and Xcode 3.1.4. So no chance there? No chance at all in OSX 10.5? In the doc for NSThread:setName, it says available in Mac OS X v10.5 and later.
Albert
The docs say supported from 10.5 on.
Georg Fritzsche
Yes, but the threadname is not propagated from the Objective-C layer to the runtime threads layer in 10.5, because the pthread_setname_np API doesn't exist until 10.6, and you need Xcode 3.2 to fetch and display the thread name.
cdespinosa
So, Xcode 3.2 on MacOSX 10.5 would be able to display thread names if I propagate the threadnames to the runtime threads layer? How can I do that?
Albert
No, Xcode 3.2 is 10.6 only. If you want to see thread names in the Xcode UI, you have to use Xcode 3.2 on Mac OS X 10.6.
cdespinosa
Just want to say this explicitely for other readers: pthread_setname_np is the solution.
Albert
A: 

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)

Dave H