NSThread VS pthreads

发布于 2024-10-06 10:33:35 字数 117 浏览 9 评论 0原文

NSThread 和 pthread 有什么区别? NSThread 是否使用 pthread 作为其内部实现?当 pthreads 足够时(特别是在 iPhone 上),我们是否真的需要 NSThread 的额外开销。

What is the difference between NSThread and pthread? Does NSThread use pthread as its internal implementation and do we really need the extra overhead of NSThread when pthreads suffice especially on the iPhone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早乙女 2024-10-13 10:33:35

我不确定 NSThread 是否在内部使用 pthreads 库。可能是这样,但由于我们没有 NSThread 的源代码,我们真的不知道。

区别在于,pthread 是一个C 库,而NSThread 是一个Objective-C 库。但它们都完成相同的功能。

如果您需要将Objective-C 库与Objective-C API 的其他部分结合使用,则需要使用Objective-C 库。 IE 中,您将无法在 NSArray存储 pthread。

I don't know for sure if NSThread use pthreads library internally. It probably does, but since we don't have source code for NSThread we really don't know.

The difference is that pthread is a C library and NSThread is an Objective-C library. But they both accomplish the same functionality.

The need for an Objective-C library is if you need to use it in combination with other portions of Objective-C API. I.E., you won't be able to store a pthread in a NSArray.

陈年往事 2024-10-13 10:33:35

据我所知 NSThread 不使用 p 线程,除非 Apple 进行了根本性的改变。对于 POSIX 标准来说,OOPC 的根源还为时过早(pthreads 出现于 1c,我认为是 1995 年)。这是针对当前 Objective-C 运行时的众多批评之一。请参阅http://www.jot.fm/issues/issue_2009_01/article4.pdf 但是,您可以通过标准 C 库访问 Objective-C 中的 pthread。我们实际上在一个项目中做出了这个假设,并且在与我们使用 pthreads 构建的库交互时遇到了问题(这是围绕使用 NSNotificationQueue 的运行循环)。

As far as I know NSThread does not use p-threads, unless Apple has radically changed things. The roots of OOPC were too early for the POSIX standard (pthreads came about in 1c, which was 1995 I think). This is one of many criticisms leveled at current Objective-C runtimes. See http://www.jot.fm/issues/issue_2009_01/article4.pdf You can, however access pthreads in Objective-C through the standard C libraries. We actually had made this assumption in a project and ran into issues when interacting with a library we built using pthreads (this was around run loops with NSNotificationQueue).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文