objective-cxcodensthread

po [NSThread currentThread]


When I do po [NSThread currentThread], I got

{name = (null), num = 4}

When I look to the left I see: enter image description here

Looks like it's Thread number 6, not 4. Also what properties do we need to call to get that thread numbers anyway?

[NSThread currentThread].number? Doesn't exist though.


Solution

  • Thread numbers are meaningless, pretty much.

    The thread instance, though, is a singleton per thread. You could use the NSThread's address, by coincidence. Better, still, would be to dip down to the mach_* API and grab the thread ID from that API.

    [NSThread currentThread] is about as unique of a number as you'll get. If the thread terminates and then a new thread is created, you might see the same address vended. The mach APIs will vend something just about as unique, really.

    What are you trying to do?