I went ahead and wrote out @xlc's suggestion, just because:
@implementation NSThread (ThreadGetIndex)
-(NSInteger)getThreadNum
{
NSString * description = [ self description ] ;
NSArray * keyValuePairs = [ description componentsSeparatedByString:@"," ] ;
for( NSString * keyValuePair in keyValuePairs )
{
NSArray * components = [ keyValuePair componentsSeparatedByString:@"=" ] ;
NSString * key = components[0] ;
key = [ key stringByTrimmingCharactersInSet:[ NSCharacterSet whitespaceCharacterSet ] ] ;
if ( [ key isEqualToString:@"num" ] )
{
return [ components[1] integerValue ] ;
}
}
@throw @"couldn't get thread num";
return -1 ;
}
@end
This answers the question of getting "num" from the thread--although the question linked as a dupe might be helpful for the general question of uniquely identifying threads.
(The answer I like there is "generate a UUID and put in in the thread's thread dictionary.)