po [NSThread 当前线程]
当我执行 po [NSThread currentThread] 时,我得到
{name = (null), num = 4}
当我向左看时,我看到:
看起来线程号是 6,而不是 4。另外,我们需要调用哪些属性来获取该线程无论如何?
[NSThread 当前线程].number?但不存在。
When I do po [NSThread currentThread], I got
{name = (null), num = 4}
When I look to the left I see:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
线程数几乎毫无意义。
不过,线程实例是每个线程的单例。巧合的是,您可以使用 NSThread 的地址。更好的方法是深入到 mach_* API 并从该 API 中获取线程 ID。
[NSThread currentThread]
是您所得到的唯一的数字。如果线程终止然后创建一个新线程,您可能会看到相同的地址被出售。 mach API 确实会提供一些同样独特的东西。你想做什么?
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?
对于斯威夫特 5:
它是一个私有变量,但可以使用 keypath 直接访问:
For Swift 5:
It's a private variable, but accessible directly using keypath:
这是我发布到 iOS 上的 NSThread number? 的答案:
Here's the answer I posted to NSThread number on iOS?: