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 iPho开发者_如何学Pythonne.
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
.
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
).
精彩评论