What type of threads does OS X have?

我怕爱的太早我们不能终老 提交于 2019-12-23 15:49:40

问题


Kernel-level threads (like Linux and some *BSD systems) or something else? If there is any difference, I'm using pthreads.


回答1:


They are Mach threads.




回答2:


Old question, but could use some more detail and accuracy:

The underlying threads in XNU (the OS X and iOS kernel) are indeed Mach threads, but these are generally hidden from user mode. Instead, there are BSD threads (also known as uthreads) over them, which are more accessible via the system calls (such as #360, bsdthread_create, and friends). PThreads actually further wrap these threads. In this way, a call to pthread create falls through to the system call bsdthread_create, which in turn (in kernel mode) invokes thread_create.

Mach calls can be called directly from user mode (via the Mach Interface Generator, MIG generated files in /usr/include/mach/*). This comes in very useful for debugging/tracing/hacking threads. But otherwise, for all intents UNIX-like, you're better off with the pthreads wrapper which (for the most part) is portable.



来源:https://stackoverflow.com/questions/4466457/what-type-of-threads-does-os-x-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!