Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set a threadname in MacOSX

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

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.


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?
like image 935
Albert Avatar asked Jan 13 '10 15:01

Albert


2 Answers

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)

like image 107
Dave H Avatar answered Oct 07 '22 23:10

Dave H


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

like image 29
cdespinosa Avatar answered Oct 08 '22 00:10

cdespinosa