Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type of threads does OS X have?

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

like image 796
Pyetras Avatar asked Dec 28 '22 03:12

Pyetras


1 Answers

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.

like image 82
Technologeeks Avatar answered Dec 31 '22 15:12

Technologeeks