Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 547
user4951 Avatar asked Mar 05 '26 01:03

user4951


2 Answers

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?

like image 119
bbum Avatar answered Mar 07 '26 19:03

bbum


For Swift 5: It's a private variable, but accessible directly using keypath:

Thread.current.value(forKeyPath: "private.seqNum")!
like image 28
The Camster Avatar answered Mar 07 '26 19:03

The Camster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!